forked from townforge/townforge
unit_tests: fix redeem_account tests and add tests for pm keys
This commit is contained in:
parent
a7648d69fa
commit
abe2314fad
@ -813,6 +813,16 @@ private:
|
||||
|
||||
crypto::public_key TestDB::DEAD_PKEY = crypto::null_pkey;
|
||||
|
||||
void inc(crypto::public_key &k)
|
||||
{
|
||||
for (int n = 0; n < 32; ++n)
|
||||
{
|
||||
++(unsigned char&)k.data[n];
|
||||
if (k.data[n] != 0)
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
TEST(cc_command, tx_defaults_to_none)
|
||||
@ -1214,6 +1224,8 @@ TEST(cc_command, execute_redeem_account)
|
||||
redeem_account.name = "redeem-test";
|
||||
redeem_account.inviting_account = TEST_ACCOUNT;
|
||||
redeem_account.invitation = inner;
|
||||
redeem_account.pmspk = crypto::null_pkey;
|
||||
redeem_account.pmvpk = crypto::null_pkey;
|
||||
sign_invitation(redeem_account, &crypto::null_hash, pkey, secret_key);
|
||||
test_commands(false, setup, redeem_account, "signature on the wrong message");
|
||||
|
||||
@ -1222,6 +1234,8 @@ TEST(cc_command, execute_redeem_account)
|
||||
redeem_account.name = "redeem-test";
|
||||
redeem_account.inviting_account = TEST_ACCOUNT;
|
||||
redeem_account.invitation = inner;
|
||||
redeem_account.pmspk = crypto::null_pkey;
|
||||
redeem_account.pmvpk = crypto::null_pkey;
|
||||
sign_invitation(redeem_account, NULL, derived_pkey, derived_skey);
|
||||
test_commands(false, setup, redeem_account, "signature with the wrong key");
|
||||
|
||||
@ -1230,6 +1244,8 @@ TEST(cc_command, execute_redeem_account)
|
||||
redeem_account.name = "redeem-test";
|
||||
redeem_account.inviting_account = TEST_ACCOUNT - 1;
|
||||
redeem_account.invitation = inner;
|
||||
redeem_account.pmspk = crypto::null_pkey;
|
||||
redeem_account.pmvpk = crypto::null_pkey;
|
||||
sign_invitation(redeem_account, NULL, pkey, secret_key);
|
||||
test_commands(false, setup, redeem_account, "wrong inviting account");
|
||||
|
||||
@ -1238,6 +1254,8 @@ TEST(cc_command, execute_redeem_account)
|
||||
redeem_account.name = "redeem-test";
|
||||
redeem_account.inviting_account = TEST_ACCOUNT;
|
||||
redeem_account.invitation = inner;
|
||||
redeem_account.pmspk = crypto::null_pkey;
|
||||
redeem_account.pmvpk = crypto::null_pkey;
|
||||
sign_invitation(redeem_account, NULL, pkey, secret_key);
|
||||
redeem_account.public_key = keys3.pub;
|
||||
test_commands(false, setup, redeem_account, "miner intercepts");
|
||||
@ -1247,6 +1265,8 @@ TEST(cc_command, execute_redeem_account)
|
||||
redeem_account.name = "";
|
||||
redeem_account.inviting_account = TEST_ACCOUNT;
|
||||
redeem_account.invitation = inner;
|
||||
redeem_account.pmspk = crypto::null_pkey;
|
||||
redeem_account.pmvpk = crypto::null_pkey;
|
||||
sign_invitation(redeem_account, NULL, pkey, secret_key);
|
||||
test_commands(false, setup, redeem_account, "empty name");
|
||||
|
||||
@ -1255,6 +1275,8 @@ TEST(cc_command, execute_redeem_account)
|
||||
redeem_account.name = " a";
|
||||
redeem_account.inviting_account = TEST_ACCOUNT;
|
||||
redeem_account.invitation = inner;
|
||||
redeem_account.pmspk = crypto::null_pkey;
|
||||
redeem_account.pmvpk = crypto::null_pkey;
|
||||
sign_invitation(redeem_account, NULL, pkey, secret_key);
|
||||
test_commands(false, setup, redeem_account, "invalid name");
|
||||
|
||||
@ -1263,7 +1285,11 @@ TEST(cc_command, execute_redeem_account)
|
||||
redeem_account.name = "redeem-test";
|
||||
redeem_account.inviting_account = TEST_ACCOUNT;
|
||||
redeem_account.invitation = inner;
|
||||
redeem_account.pmspk = crypto::null_pkey;
|
||||
redeem_account.pmvpk = crypto::null_pkey;
|
||||
MGINFO("Before sign: " << redeem_account.pmspk << " " << redeem_account.pmvpk);
|
||||
sign_invitation(redeem_account, NULL, pkey, secret_key);
|
||||
MGINFO("After sign: " << redeem_account.pmspk << " " << redeem_account.pmvpk);
|
||||
test_commands(true, setup, redeem_account, "valid");
|
||||
|
||||
// invitation with a recipient
|
||||
@ -1279,6 +1305,8 @@ TEST(cc_command, execute_redeem_account)
|
||||
redeem_account.name = "redeem-test-with-recipient";
|
||||
redeem_account.inviting_account = TEST_ACCOUNT;
|
||||
redeem_account.invitation = inner;
|
||||
redeem_account.pmspk = crypto::null_pkey;
|
||||
redeem_account.pmvpk = crypto::null_pkey;
|
||||
sign_invitation(redeem_account, NULL, pkey, secret_key, &keys2);
|
||||
test_commands(false, setup, redeem_account, "bad recipient");
|
||||
|
||||
@ -1290,11 +1318,34 @@ TEST(cc_command, execute_redeem_account)
|
||||
ASSERT_EQ(amount, 420);
|
||||
ASSERT_EQ(recipient, keys2.pub);
|
||||
|
||||
// invalid pmspk
|
||||
redeem_account.public_key = keys2.pub;
|
||||
redeem_account.name = "redeem-test-with-recipient";
|
||||
redeem_account.inviting_account = TEST_ACCOUNT;
|
||||
redeem_account.invitation = inner;
|
||||
redeem_account.pmspk = crypto::null_pkey;
|
||||
do inc(redeem_account.pmspk); while (check_key(redeem_account.pmspk));
|
||||
redeem_account.pmvpk = crypto::null_pkey;
|
||||
sign_invitation(redeem_account, NULL, pkey, secret_key, &keys2);
|
||||
test_commands(false, setup, redeem_account, "invalid pmspk");
|
||||
|
||||
// invalid pmvpk
|
||||
redeem_account.public_key = keys2.pub;
|
||||
redeem_account.name = "redeem-test-with-recipient";
|
||||
redeem_account.inviting_account = TEST_ACCOUNT;
|
||||
redeem_account.invitation = inner;
|
||||
redeem_account.pmspk = crypto::null_pkey;
|
||||
do inc(redeem_account.pmvpk); while (check_key(redeem_account.pmvpk));
|
||||
sign_invitation(redeem_account, NULL, pkey, secret_key, &keys2);
|
||||
test_commands(false, setup, redeem_account, "invalid pmvpk");
|
||||
|
||||
// good
|
||||
redeem_account.public_key = keys2.pub;
|
||||
redeem_account.name = "redeem-test-with-recipient";
|
||||
redeem_account.inviting_account = TEST_ACCOUNT;
|
||||
redeem_account.invitation = inner;
|
||||
redeem_account.pmspk = crypto::null_pkey;
|
||||
redeem_account.pmvpk = crypto::null_pkey;
|
||||
sign_invitation(redeem_account, NULL, pkey, secret_key, &keys2);
|
||||
test_commands(true, setup, redeem_account, "valid with recipient");
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user