Browse Source

Add test for non-malleable txids. To run just this test:

./zcash-gtest --gtest_filter="txid_tests*"
pull/145/head
Simon 8 years ago
parent
commit
2a7fde3f42
  1. 1
      src/Makefile.gtest.include
  2. 45
      src/gtest/test_txid.cpp

1
src/Makefile.gtest.include

@ -11,6 +11,7 @@ zcash_gtest_SOURCES = \
gtest/test_noteencryption.cpp \
gtest/test_merkletree.cpp \
gtest/test_circuit.cpp \
gtest/test_txid.cpp \
gtest/test_libzcash_utils.cpp
zcash_gtest_CPPFLAGS = -DMULTICORE -fopenmp -DBINARY_OUTPUT -DCURVE_ALT_BN128 -DSTATIC

45
src/gtest/test_txid.cpp

@ -0,0 +1,45 @@
#include <gtest/gtest.h>
#include "primitives/transaction.h"
#include "clientversion.h"
#include "serialize.h"
#include "streams.h"
#include "uint256.h"
#include "util.h"
#include "utilstrencodings.h"
/*
* scriptSig=3045022100ba5e90204e83c5f961b67c6232c1cc6c360afd36d43fcfae0de7af2e75f4cda7022012fec415a12048dbb70511fda6195b090b56735232281dc1144409833a092edc01
* rawtx:
* withsig: 01000000015ad78be5497476bbf84869d8156761ca850b6e82e48ad1315069a3726516a3d1010000006b483045022100ba5e90204e83c5f961b67c6232c1cc6c360afd36d43fcfae0de7af2e75f4cda7022012fec415a12048dbb70511fda6195b090b56735232281dc1144409833a092edc012102c322382e17c9ed4f47183f219cc5dd7853f939fb8eebae3c943622e0abf8d5e5feffffff0280969800000000001976a91430271a250e92135ce0db0783ebb63aaeb58e47f988acd694693a000000001976a9145f0d00adba6489150808feb4108d7be582cbb2e188ac0a000000
* without: 01000000015ad78be5497476bbf84869d8156761ca850b6e82e48ad1315069a3726516a3d10100000000feffffff0280969800000000001976a91430271a250e92135ce0db0783ebb63aaeb58e47f988acd694693a000000001976a9145f0d00adba6489150808feb4108d7be582cbb2e188ac0a000000
*/
TEST(txid_tests, check_txid_and_hash_are_different) {
// Random zcash transaction 19cfa5db35f33a2e67fe1b9b738731b62e548d2f27c55a2f28523fec52b71525
CTransaction tx;
CDataStream stream(ParseHex("01000000015ad78be5497476bbf84869d8156761ca850b6e82e48ad1315069a3726516a3d1010000006b483045022100ba5e90204e83c5f961b67c6232c1cc6c360afd36d43fcfae0de7af2e75f4cda7022012fec415a12048dbb70511fda6195b090b56735232281dc1144409833a092edc012102c322382e17c9ed4f47183f219cc5dd7853f939fb8eebae3c943622e0abf8d5e5feffffff0280969800000000001976a91430271a250e92135ce0db0783ebb63aaeb58e47f988acd694693a000000001976a9145f0d00adba6489150808feb4108d7be582cbb2e188ac0a000000"), SER_DISK, CLIENT_VERSION);
stream >> tx;
uint256 txid = uint256S("0x19cfa5db35f33a2e67fe1b9b738731b62e548d2f27c55a2f28523fec52b71525");
ASSERT_TRUE(txid==tx.GetTxid());
uint256 hash = uint256S("0xaacaa62d40fcdd9192ed35ea9df31660ccf7f6c60566530faaa444fb5d0d410e");
ASSERT_TRUE(hash!=tx.GetTxid());
}
/*
* coinbase txid is the double sha256, sigscript is not skipped because of BIP34.
* txid: 6041357de59ba64959d1b60f93de24dfe5ea1e26ed9e8a73d35b225a1845bad5
* raw: 01000000010000000000000000000000000000000000000000000000000000000000000000ffffffff03530101ffffffff02f049020000000000232102f2df427fd4f76552ed0e86b17da8cf9b07754ea23ddc05799410a4a3a5d806ccac7c9200000000000017a9146708e6670db0b950dac68031025cc5b63213a4918700000000
*/
TEST(txid_tests, check_txid_and_hash_are_same_coinbase) {
// Random zcash coinbase transaction 6041357de59ba64959d1b60f93de24dfe5ea1e26ed9e8a73d35b225a1845bad5
CTransaction tx;
CDataStream stream(ParseHex("01000000010000000000000000000000000000000000000000000000000000000000000000ffffffff03530101ffffffff02f049020000000000232102f2df427fd4f76552ed0e86b17da8cf9b07754ea23ddc05799410a4a3a5d806ccac7c9200000000000017a9146708e6670db0b950dac68031025cc5b63213a4918700000000"), SER_DISK, CLIENT_VERSION);
stream >> tx;
ASSERT_TRUE(tx.IsCoinBase());
uint256 hash = uint256S("6041357de59ba64959d1b60f93de24dfe5ea1e26ed9e8a73d35b225a1845bad5");
ASSERT_TRUE(hash==tx.GetTxid());
}
Loading…
Cancel
Save