cleanups
This commit is contained in:
@@ -3,7 +3,7 @@
|
||||
|
||||
#include "base58.h"
|
||||
#include "key.h"
|
||||
#include "komodo_cc.h"
|
||||
#include "script/cc.h"
|
||||
#include "cc/eval.h"
|
||||
#include "primitives/transaction.h"
|
||||
#include "script/interpreter.h"
|
||||
@@ -93,20 +93,21 @@ TEST_F(CCTest, testMayAcceptCryptoCondition)
|
||||
}
|
||||
|
||||
|
||||
static bool CCVerify(const CMutableTransaction &mtxTo, const CC *cond) {
|
||||
CAmount amount;
|
||||
ScriptError error;
|
||||
CTransaction txTo(mtxTo);
|
||||
PrecomputedTransactionData txdata(txTo);
|
||||
auto checker = ServerTransactionSignatureChecker(&txTo, 0, amount, false, txdata);
|
||||
return VerifyScript(CCSig(cond), CCPubKey(cond), 0, checker, 0, &error);
|
||||
};
|
||||
|
||||
|
||||
TEST_F(CCTest, testVerifyCryptoCondition)
|
||||
{
|
||||
CC *cond;
|
||||
ScriptError error;
|
||||
CMutableTransaction mtxTo;
|
||||
|
||||
auto Verify = [&] (const CC *cond) {
|
||||
CAmount amount;
|
||||
CTransaction txTo(mtxTo);
|
||||
PrecomputedTransactionData txdata(txTo);
|
||||
auto checker = ServerTransactionSignatureChecker(&txTo, 0, amount, false, txdata);
|
||||
return VerifyScript(CCSig(cond), CCPubKey(cond), 0, checker, 0, &error);
|
||||
};
|
||||
|
||||
// ok
|
||||
cond = CCNewSecp256k1(notaryKey.GetPubKey());
|
||||
CCFromJson(cond, R"!!({
|
||||
@@ -114,7 +115,7 @@ TEST_F(CCTest, testVerifyCryptoCondition)
|
||||
"publicKey": "0205a8ad0c1dbc515f149af377981aab58b836af008d4d7ab21bd76faf80550b47"
|
||||
})!!");
|
||||
CCSign(mtxTo, cond);
|
||||
ASSERT_TRUE(Verify(cond));
|
||||
ASSERT_TRUE(CCVerify(mtxTo, cond));
|
||||
|
||||
|
||||
// has signature nodes
|
||||
@@ -128,18 +129,18 @@ TEST_F(CCTest, testVerifyCryptoCondition)
|
||||
})!!");
|
||||
cond->threshold = 2;
|
||||
CCSign(mtxTo, cond);
|
||||
ASSERT_TRUE(Verify(cond));
|
||||
ASSERT_TRUE(CCVerify(mtxTo, cond));
|
||||
|
||||
// no signatures; the preimage will get encoded as a fulfillment because it's cheaper
|
||||
// and the secp256k1 node will get encoded as a condition
|
||||
cond->threshold = 1;
|
||||
ASSERT_FALSE(Verify(cond));
|
||||
ASSERT_FALSE(CCVerify(mtxTo, cond));
|
||||
|
||||
// here the signature is set wrong
|
||||
cond->threshold = 2;
|
||||
ASSERT_TRUE(Verify(cond));
|
||||
ASSERT_TRUE(CCVerify(mtxTo, cond));
|
||||
memset(cond->subconditions[1]->signature, 0, 32);
|
||||
ASSERT_FALSE(Verify(cond));
|
||||
ASSERT_FALSE(CCVerify(mtxTo, cond));
|
||||
}
|
||||
|
||||
extern Eval* EVAL_TEST;
|
||||
@@ -159,24 +160,15 @@ TEST_F(CCTest, testVerifyEvalCondition)
|
||||
|
||||
|
||||
CC *cond;
|
||||
ScriptError error;
|
||||
CMutableTransaction mtxTo;
|
||||
|
||||
auto Verify = [&] (const CC *cond) {
|
||||
CAmount amount;
|
||||
CTransaction txTo(mtxTo);
|
||||
PrecomputedTransactionData txdata(txTo);
|
||||
auto checker = ServerTransactionSignatureChecker(&txTo, 0, amount, false, txdata);
|
||||
return VerifyScript(CCSig(cond), CCPubKey(cond), 0, checker, 0, &error);
|
||||
};
|
||||
|
||||
// ok
|
||||
cond = CCNewThreshold(2, { CCNewSecp256k1(notaryKey.GetPubKey()), CCNewEval({1}) });
|
||||
CCSign(mtxTo, cond);
|
||||
ASSERT_TRUE(Verify(cond));
|
||||
ASSERT_TRUE(CCVerify(mtxTo, cond));
|
||||
|
||||
cond->subconditions[1]->code[0] = 0;
|
||||
ASSERT_FALSE(Verify(cond));
|
||||
ASSERT_FALSE(CCVerify(mtxTo, cond));
|
||||
}
|
||||
|
||||
|
||||
@@ -186,24 +178,16 @@ TEST_F(CCTest, testCryptoConditionsDisabled)
|
||||
ScriptError error;
|
||||
CMutableTransaction mtxTo;
|
||||
|
||||
auto Verify = [&] (const CC *cond) {
|
||||
CAmount amount;
|
||||
CTransaction txTo(mtxTo);
|
||||
PrecomputedTransactionData txdata(txTo);
|
||||
auto checker = ServerTransactionSignatureChecker(&txTo, 0, amount, false, txdata);
|
||||
return VerifyScript(CCSig(cond), CCPubKey(cond), 0, checker, 0, &error);
|
||||
};
|
||||
|
||||
// ok
|
||||
CCFromJson(cond, R"!!({
|
||||
"type": "secp256k1-sha-256",
|
||||
"publicKey": "0205a8ad0c1dbc515f149af377981aab58b836af008d4d7ab21bd76faf80550b47"
|
||||
})!!");
|
||||
CCSign(mtxTo, cond);
|
||||
ASSERT_TRUE(Verify(cond));
|
||||
ASSERT_TRUE(CCVerify(mtxTo, cond));
|
||||
|
||||
ASSETCHAINS_CC = 0;
|
||||
ASSERT_FALSE(Verify(cond));
|
||||
ASSERT_FALSE(CCVerify(mtxTo, cond));
|
||||
}
|
||||
|
||||
|
||||
@@ -213,14 +197,6 @@ TEST_F(CCTest, testLargeCondition)
|
||||
ScriptError error;
|
||||
CMutableTransaction mtxTo;
|
||||
|
||||
auto Verify = [&] (const CC *cond) {
|
||||
CAmount amount;
|
||||
CTransaction txTo(mtxTo);
|
||||
PrecomputedTransactionData txdata(txTo);
|
||||
auto checker = ServerTransactionSignatureChecker(&txTo, 0, amount, false, txdata);
|
||||
return VerifyScript(CCSig(cond), CCPubKey(cond), 0, checker, 0, &error);
|
||||
};
|
||||
|
||||
std::vector<CC*> ccs;
|
||||
for (int i=0; i<18; i++) {
|
||||
ccs.push_back(CCNewSecp256k1(notaryKey.GetPubKey()));
|
||||
@@ -230,5 +206,5 @@ TEST_F(CCTest, testLargeCondition)
|
||||
EXPECT_EQ("(16 of 5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,A5,A5)",
|
||||
CCShowStructure(CCPrune(cond)));
|
||||
EXPECT_EQ(1744, CCSig(cond).size());
|
||||
ASSERT_TRUE(Verify(cond));
|
||||
ASSERT_TRUE(CCVerify(mtxTo, cond));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user