Browse Source

cleanups

pull/4/head
Scott Sadler 6 years ago
parent
commit
8a8e10f02f
  1. 2
      src/Makefile.am
  2. 2
      src/cc/betprotocol.cpp
  3. 4
      src/cc/disputepayout.cpp
  4. 2
      src/cc/eval.cpp
  5. 1
      src/cryptoconditions/.gitignore
  6. 2
      src/rpcblockchain.cpp
  7. 2
      src/script/cc.cpp
  8. 6
      src/script/cc.h
  9. 2
      src/script/interpreter.h
  10. 2
      src/script/script.cpp
  11. 2
      src/script/serverchecker.cpp
  12. 2
      src/script/standard.cpp
  13. 66
      src/test-komodo/test_cryptoconditions.cpp
  14. 2
      src/test-komodo/test_eval_bet.cpp
  15. 4
      src/test-komodo/test_eval_notarisation.cpp
  16. 2
      src/test-komodo/testutils.h

2
src/Makefile.am

@ -381,13 +381,13 @@ libbitcoin_common_a_SOURCES = \
hash.cpp \
key.cpp \
keystore.cpp \
komodo_cc.cpp \
netbase.cpp \
primitives/block.cpp \
primitives/transaction.cpp \
protocol.cpp \
pubkey.cpp \
scheduler.cpp \
script/cc.cpp \
script/interpreter.cpp \
script/script.cpp \
script/script_error.cpp \

2
src/cc/betprotocol.cpp

@ -1,7 +1,7 @@
#include <cryptoconditions.h>
#include "streams.h"
#include "komodo_cc.h"
#include "script/cc.h"
#include "cc/eval.h"
#include "cc/betprotocol.h"
#include "primitives/transaction.h"

4
src/cc/disputepayout.cpp

@ -3,7 +3,7 @@
#include "hash.h"
#include "chain.h"
#include "version.h"
#include "komodo_cc.h"
#include "script/cc.h"
#include "cc/eval.h"
#include "cc/betprotocol.h"
#include "primitives/transaction.h"
@ -61,7 +61,7 @@ bool Eval::DisputePayout(AppVM &vm, std::vector<uint8_t> params, const CTransact
for (int i=1; i<spends.size(); i++)
{
std::vector<unsigned char> vmState;
if (!spends[i].vout.size() > 0) continue;
if (spends[i].vout.size() == 0) continue;
if (!GetOpReturnData(spends[i].vout[0].scriptPubKey, vmState)) continue;
auto out = vm.evaluate(vmParams, vmState);
uint256 resultHash = SerializeHash(out.second);

2
src/cc/eval.cpp

@ -2,7 +2,7 @@
#include <cryptoconditions.h>
#include "primitives/transaction.h"
#include "komodo_cc.h"
#include "script/cc.h"
#include "cc/eval.h"
#include "main.h"
#include "chain.h"

1
src/cryptoconditions/.gitignore

@ -22,4 +22,3 @@
converter-sample.c
config.*
.pytest_cache
src/asn/asn_system.h

2
src/rpcblockchain.cpp

@ -633,7 +633,7 @@ UniValue txMoMproof(const UniValue& params, bool fHelp)
// parse params and get notarisation data for tx
{
if ( fHelp || params.size() != 1)
throw runtime_error("txmomproof needs a txid");
throw runtime_error("txMoMproof needs a txid");
hash = uint256S(params[0].get_str());

2
src/komodo_cc.cpp → src/script/cc.cpp

@ -1,5 +1,5 @@
#include "cryptoconditions/include/cryptoconditions.h"
#include "komodo_cc.h"
#include "script/cc.h"
bool IsCryptoConditionsEnabled()

6
src/komodo_cc.h → src/script/cc.h

@ -1,5 +1,5 @@
#ifndef KOMODO_CC_H
#define KOMODO_CC_H
#ifndef SCRIPT_CC_H
#define SCRIPT_CC_H
#include "pubkey.h"
#include "script/script.h"
@ -80,4 +80,4 @@ bool GetPushData(const CScript &sig, std::vector<unsigned char> &data);
bool GetOpReturnData(const CScript &sig, std::vector<unsigned char> &data);
#endif /* KOMODO_CC_H */
#endif /* SCRIPT_CC_H */

2
src/script/interpreter.h

@ -8,7 +8,7 @@
#include "script_error.h"
#include "primitives/transaction.h"
#include "komodo_cc.h"
#include "script/cc.h"
#include <vector>
#include <stdint.h>

2
src/script/script.cpp

@ -7,7 +7,7 @@
#include "tinyformat.h"
#include "utilstrencodings.h"
#include "komodo_cc.h"
#include "script/cc.h"
#include "cryptoconditions/include/cryptoconditions.h"
namespace {

2
src/script/serverchecker.cpp

@ -4,7 +4,7 @@
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
#include "serverchecker.h"
#include "komodo_cc.h"
#include "script/cc.h"
#include "cc/eval.h"
#include "pubkey.h"

2
src/script/standard.cpp

@ -9,7 +9,7 @@
#include "script/script.h"
#include "util.h"
#include "utilstrencodings.h"
#include "komodo_cc.h"
#include "script/cc.h"
#include <boost/foreach.hpp>

66
src/test-komodo/test_cryptoconditions.cpp

@ -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));
}

2
src/test-komodo/test_eval_bet.cpp

@ -6,7 +6,7 @@
#include "base58.h"
#include "key.h"
#include "main.h"
#include "komodo_cc.h"
#include "script/cc.h"
#include "primitives/transaction.h"
#include "script/interpreter.h"
#include "script/serverchecker.h"

4
src/test-komodo/test_eval_notarisation.cpp

@ -7,7 +7,7 @@
#include "core_io.h"
#include "key.h"
#include "main.h"
#include "komodo_cc.h"
#include "script/cc.h"
#include "primitives/transaction.h"
#include "script/interpreter.h"
#include "script/serverchecker.h"
@ -111,6 +111,8 @@ TEST(TestEvalNotarisation, testGetNotarisation)
MoMProof proof;
E_UNMARSHAL(vMomProof, ss >> proof);
printf("lb:%lu\n", proof.branch.size());
printf("%i, %s\n", proof.nIndex, proof.notarisationHash.GetHex().data());
EXPECT_EQ(data.MoM, proof.Exec(proofTxHash));
}

2
src/test-komodo/testutils.h

@ -1,7 +1,7 @@
#ifndef TESTUTILS_H
#define TESTUTILS_H
#include "komodo_cc.h"
#include "script/cc.h"
#define VCH(a,b) std::vector<unsigned char>(a, a + b)

Loading…
Cancel
Save