From 054b77dbde5404ca2e252d5c7eecdd62d3d11cd0 Mon Sep 17 00:00:00 2001 From: Evgenii Stratonikov Date: Tue, 18 Aug 2020 13:45:24 +0300 Subject: [PATCH 1/4] block: update binary test data --- pkg/core/block/block_test.go | 148 ++++++++++++-------------------- pkg/core/block/helper_test.go | 3 +- pkg/core/test_data/block_1.json | 64 ++++++++------ pkg/core/test_data/block_2.json | 47 ++++------ 4 files changed, 114 insertions(+), 148 deletions(-) diff --git a/pkg/core/block/block_test.go b/pkg/core/block/block_test.go index 0d64ff80b..9795d465c 100644 --- a/pkg/core/block/block_test.go +++ b/pkg/core/block/block_test.go @@ -1,18 +1,28 @@ package block import ( + "encoding/base64" + "encoding/hex" + "strings" "testing" "github.com/nspcc-dev/neo-go/pkg/config/netmode" "github.com/nspcc-dev/neo-go/pkg/core/transaction" "github.com/nspcc-dev/neo-go/pkg/crypto/hash" + "github.com/nspcc-dev/neo-go/pkg/encoding/address" + "github.com/nspcc-dev/neo-go/pkg/internal/testserdes" + "github.com/nspcc-dev/neo-go/pkg/io" "github.com/nspcc-dev/neo-go/pkg/vm/opcode" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" ) -// Test blocks are blocks from mainnet with their corresponding index. -// TODO NEO3.0: Update binary -/* +func trim0x(value interface{}) string { + s := value.(string) + return strings.TrimPrefix(s, "0x") +} + +// Test blocks are blocks from testnet with their corresponding index. func TestDecodeBlock1(t *testing.T) { data, err := getBlockData(1) require.NoError(t, err) @@ -20,25 +30,25 @@ func TestDecodeBlock1(t *testing.T) { b, err := hex.DecodeString(data["raw"].(string)) require.NoError(t, err) - block := &Block{} + block := New(netmode.TestNet) assert.NoError(t, testserdes.DecodeBinary(b, block)) assert.Equal(t, uint32(data["index"].(float64)), block.Index) assert.Equal(t, uint32(data["version"].(float64)), block.Version) - assert.Equal(t, data["hash"].(string), block.Hash().StringLE()) - assert.Equal(t, data["previousblockhash"].(string), block.PrevHash.StringLE()) - assert.Equal(t, data["merkleroot"].(string), block.MerkleRoot.StringLE()) - assert.Equal(t, data["nextconsensus"].(string), address.Uint160ToString(block.NextConsensus)) + assert.Equal(t, trim0x(data["hash"]), block.Hash().StringLE()) + assert.Equal(t, trim0x(data["previousblockhash"]), block.PrevHash.StringLE()) + assert.Equal(t, trim0x(data["merkleroot"]), block.MerkleRoot.StringLE()) + assert.Equal(t, trim0x(data["nextconsensus"]), address.Uint160ToString(block.NextConsensus)) - script := data["script"].(map[string]interface{}) - assert.Equal(t, script["invocation"].(string), hex.EncodeToString(block.Script.InvocationScript)) - assert.Equal(t, script["verification"].(string), hex.EncodeToString(block.Script.VerificationScript)) + scripts := data["witnesses"].([]interface{}) + script := scripts[0].(map[string]interface{}) + assert.Equal(t, script["invocation"].(string), base64.StdEncoding.EncodeToString(block.Script.InvocationScript)) + assert.Equal(t, script["verification"].(string), base64.StdEncoding.EncodeToString(block.Script.VerificationScript)) tx := data["tx"].([]interface{}) - minerTX := tx[0].(map[string]interface{}) + tx0 := tx[0].(map[string]interface{}) assert.Equal(t, len(tx), len(block.Transactions)) - assert.Equal(t, minerTX["type"].(string), block.Transactions[0].Type.String()) - assert.Equal(t, len(minerTX["attributes"].([]interface{})), len(block.Transactions[0].Attributes)) + assert.Equal(t, len(tx0["attributes"].([]interface{})), len(block.Transactions[0].Attributes)) } func TestTrimmedBlock(t *testing.T) { @@ -47,7 +57,7 @@ func TestTrimmedBlock(t *testing.T) { b, err := block.Trim() require.NoError(t, err) - trimmedBlock, err := NewBlockFromTrimmedBytes(b) + trimmedBlock, err := NewBlockFromTrimmedBytes(netmode.TestNet, b) require.NoError(t, err) assert.True(t, trimmedBlock.Trimmed) @@ -56,6 +66,7 @@ func TestTrimmedBlock(t *testing.T) { assert.Equal(t, block.MerkleRoot, trimmedBlock.MerkleRoot) assert.Equal(t, block.Timestamp, trimmedBlock.Timestamp) assert.Equal(t, block.Index, trimmedBlock.Index) + require.NoError(t, trimmedBlock.ConsensusData.createHash()) assert.Equal(t, block.ConsensusData, trimmedBlock.ConsensusData) assert.Equal(t, block.NextConsensus, trimmedBlock.NextConsensus) @@ -66,7 +77,7 @@ func TestTrimmedBlock(t *testing.T) { assert.True(t, trimmedBlock.Transactions[i].Trimmed) } } -*/ + func newDumbBlock() *Block { return &Block{ Base: Base{ @@ -108,51 +119,22 @@ func TestBlockVerify(t *testing.T) { assert.Nil(t, block.Verify()) } -//TODO NEO3.0: Update binary -/* func TestBinBlockDecodeEncode(t *testing.T) { // transaction taken from mainnet: 2000000 - rawtx := "00000000e5a49e24ee36e972e1bbee16c6897b88050e95e40db157d901cbb68de5243dc93482b51e7ce810eca512afe201768668de5910d4373db067418ad1cf95cd291de424a15a80841e00ec3bd62b5562099d59e75d652b5d3827bf04c165bbe9ef95cca4bf5501fd450140f9ef37e9a31614d0c42aca576d11fcd2ca4cade56143e725ab45e2c7372601e5322a89e0585b44f6f436147be6dc6513ebe781c358abadb1336cadc8f1fdf2e4407fedf529ec4b16ada7fec16efcb377e9c0ea515b12b98a8bed01c385999f8f6121dd5fad32abe4d95dc0c11e9a3a6ce093a7f550b96b779c45f584022bb8a93640d266010bee43509f70c9e7d86cd5037214718de5682abeb42141d1691a1595e5ee188393c26b9ca9f31e4db2d87c3c76869c4b02d081672909268e4d53bcc850401866a84eafd9003c17f1469f1830c5c5f2976da54991f7a1ed292a8af0de2ce202d8f15cb0f362f0ae0ee8bf43886785db45fed0d77b5254503ac105e694a7ac40bfc7166d3495ad4ab540e287ec51afc0569f292e106055b13765d6dacc1ed14807eb63cfeb04b50977c2a64735a4d7496c95f361b773dc58ae29a11b8183f717f1552102486fd15702c4490a26703112a5cc1d0923fd697a33406bd5a1c00e0013b09a7021024c7b7fb6c310fccf1ba33b082519d82964ea93868d676662d4a59ad548df0e7d2102aaec38470f6aad0042c6e877cfd8087d2676b0f516fddd362801b9bd3936399e2103b209fd4f53a7170ea4444e0cb0a6bb6a53c2bd016926989cf85f9b0fba17a70c2103b8d9d5771d8f513aa0869b9cc8d50986403b78c6da36890638c3d46a5adce04a2102ca0e27697b9c248f6f16e085fd0061e26f44da85b58ee835c110caa5ec3ba5542102df48f60e8f3e01c48ff40b9b7f1310d7a8b2a193188befe1c2e3df740e89509357ae120000ec3bd62b0000000080000001e91406db8ce12ff273d9c04cb0f224870d43eeb53c7522a6ad47b0c2ad9614cc0000019b7cffdaa674beae0f930ebe6085af9093e5fe56b34a5c220ccdcf6efc336fc5005ed0b200000000606fe152cafd010c1911b9c7932b77562d13b02f01414054f533865c49ae27ee9898f18c3ad18e2bb27928af9dbfdca44713b666f343e06416fe04869c3b5355934b101ac40caa4910cebdcfc3fec7322d12b0aa4d5bd7232103dfe98cbad29e3116324a5125a32b36250679190f74dca7425c40fff589cc530cac800000012ae528ca6f1c1a740a716603aac1e167cad482d49c41e4a356565cefa50b5dbd0000019b7cffdaa674beae0f930ebe6085af9093e5fe56b34a5c220ccdcf6efc336fc5008d190207000000be87c8c3cb58ca27e5235c5d451474435b895386014140fe20765111b9845d7d842cf09205931ea35e0de5d7078c3831e2b36e41e2298a1cf3d8bc697676ae48a577d70757ecf262085ed314c2d077e0e7a11830dc1b7d232103f2ad7aebe26d46541cb99deb3ff06fd24f0b87efa7e52a1aba6a2d3167be6044acd1015b0600a0724e1809146063795d3b9b3cd55aef026eae992b91063db0db1458f310994f5561f8759ebbdab2e87a05fa4d256553c1087472616e7366657267f91d6b7085db7c5aaf09f19eeec1ca3c0db2c6ecf166aacd14a39b8747f90000000000000000012058f310994f5561f8759ebbdab2e87a05fa4d25650000014140664803b370fb1125fccb44b470a9062d2f1108f4b9c43b7aa35fd56eb52c0564c72e649eefacf82bfb25d252aef5e677307bd0142cecc60e369265b3d053a8d9232103a95af1ee45fe9a2cbad6358e3357da7a13e994361b385c72141ca5a47ef993f6ac800000028190ef017f831707830dd8dc2867572136e7d73bdc13a7421433072e36830c6c00008190ef017f831707830dd8dc2867572136e7d73bdc13a7421433072e36830c6c010001e72d286979ee6cb1b7e65dfddfb2e384100b8d148e7758de42e4168b71792c600300000000000000494a6c348bdcbf192fb1a88ee41883fcdd11ef37014140a2dc5f161bcb696deeae6f078702627280cfc360d5bf0cae13a417212da2bc87c207d58cca83deb3e6fd76c05bc135367eb520e0138fbfc25e05985ddfa514352321039beeb554e21dfdd414fd07844460d2d1117d26e6b6d18314c535ef25511cee16ac8000000144a1e8637a27d17be06f4d5e4483841c5db27420757350833e970861cf0f6c650500019b7cffdaa674beae0f930ebe6085af9093e5fe56b34a5c220ccdcf6efc336fc500c817a80400000034a3393450b5217977ba2efebad0dd6c37bb0a690141409f6eec2a9983ae782e3d7bdf8ce02f2c9b6db4660ee93197ed8ae85ae9ef424d421ba35a3b70738618b255ab387fe32a0dee1ccd6c0bb8d1e306e3947c383557232103994c84c3cbbc3a75be1045a2ce795d2d5733bb8425f2580e19ff7f179bb8719bac80000001e04c80df4a53b8ba9dca435630f1170d3cc6f15f508e98006ef44bf9f38de82d0000019b7cffdaa674beae0f930ebe6085af9093e5fe56b34a5c220ccdcf6efc336fc500bca06501000000d32f28fd47cc176e3d2bf6ac30eb87dfb838ef99014140b8c50990b976e837033eb09da821dae396782bd0df404e1e0675f2db9b7fc6b681b1cb6cb717a546268363f63ae65f89a18769d201b531fee4afd78b2fffb9aa232103ef4c441d2c4cd1a2e3f255366d149553a7f8f799edf1a49a0bc1af0081cc65beac80000001a6f0562becc89fd0ab4c36e2bcc4eedeb6de9fa6bb398be22dafc4e0512b55bc0000019b7cffdaa674beae0f930ebe6085af9093e5fe56b34a5c220ccdcf6efc336fc50001b2c4000000001decb55a65ad7d23a4d474a1e75ff24c9a71dcc4014140175ea6f8e03e7fbf4254ba16ccdd06a6d6c71b7b4d3965bc0913cf02f16ce3180dc278cde426f493225c4e51db28d934da120f5ef2b723585c5aafc8493071e4232103f3215374a4384eb8e2a60635f1e8394ccbe1e21a7b90e0063f5d5ac1836402ceacd100530800fee9e85100000014f9dfa019739920e7ab28544e979c0e6613f54536140a551a5ab4acf6a31dc6fc2a91d05684424a620e53c1087472616e7366657267fb1c540417067c270dee32f21023aa8b9b71abce0001243726662530e8d5576aced9b76cc57b078a9e2857e1ae1bd04869a608657f00000001e72d286979ee6cb1b7e65dfddfb2e384100b8d148e7758de42e4168b71792c6001000000000000000a551a5ab4acf6a31dc6fc2a91d05684424a620e014140fd662c8eeaeb3fdc5e9906277c79e31e521b2aa503f0e0684ce876283b27949b2366cd5034a74d7b0b0c47e0648b57a2d569378ee0f82d2bdb3717c4cb3d5c4c2321032204ffdc2173ee04c61f3dbe1ba1ca743106f7cccc7cf6fff86be5dcd6ac63d6ac02000134c42a75a09535438eda8df28e58f8fdc7c5d3329ed6f1d9a845627f7beb53410000000001e72d286979ee6cb1b7e65dfddfb2e384100b8d148e7758de42e4168b71792c60429415000000000046a030db679a5ce51ac083c73b44f0ff6729561c01414065eb2a2a52e6c34ce3a2925ec03b958eeda5cc310468f198ac9c7c111f9a62778214e9b8234c92aef5dba75a29536d6b58b8a074eeb547c53a0e26dc0eaadb86232102670e8d99a3c28d947ddfaa76416a4f53dbcde3ee3d271b1bc78941d5f6d7b829acd1015b0600a0724e1809146063795d3b9b3cd55aef026eae992b91063db0db1458f310994f5561f8759ebbdab2e87a05fa4d256553c1087472616e7366657267f91d6b7085db7c5aaf09f19eeec1ca3c0db2c6ecf1669fb73cc8cde6c72f0000000000000000012058f310994f5561f8759ebbdab2e87a05fa4d25650000014140a1cfd844d2623cfb2b867ec8bf24d3951bd7fcdd5de1e9d59a97b3e240f80020cc7612a3a7dfa32696b7837a1a38f85d27227f76a45b0e6c956abb8b68183177232103a95af1ee45fe9a2cbad6358e3357da7a13e994361b385c72141ca5a47ef993f6ac800000016ab96ecf9f3a32fd8e209d2b5650fb2d12c39bc89493421bdd290d69bbe74d540000019b7cffdaa674beae0f930ebe6085af9093e5fe56b34a5c220ccdcf6efc336fc500cf14130400000088eb48d2d1c288c0982ae188b13d5a2a994ab254014140e3269b08dfc3409031a24b7493376a9597eca37a6d6da868fda33005b596accb6e2b7ad4f137d597420d29f080ee9ba545935b47e6358f3f8c1f9118b4e4a085232102e93db927a1f516b37962c4262e78ad56b20e4d349cb1908ee612526ccd0d1118acd10153088005a34c17000000147f808fa952008067570e27dfe0fdc97f647964a51439de68a3e72a015de6ea5543dc896d8609c1c45153c1087472616e7366657267fb1c540417067c270dee32f21023aa8b9b71abce00000000000000000001cd018dd92f5209d47590d74fdd3f982e1ac86d202c12bc948a2890cdb857cff1000002e72d286979ee6cb1b7e65dfddfb2e384100b8d148e7758de42e4168b71792c60010000000000000039de68a3e72a015de6ea5543dc896d8609c1c451e72d286979ee6cb1b7e65dfddfb2e384100b8d148e7758de42e4168b71792c60a9301b000000000039de68a3e72a015de6ea5543dc896d8609c1c4510141407fad0f5501e9ce3fa9bef9d378257ce233f41d5fd4955e69367ad57392f9feac7608d90553e3e285785cf87fe01b8ab1266d9c73de1e33ceff1c51133735e39b2321028ad2a0b73a8624cc027d80b6ef4af9de5167740aede9cb6401ccc0faef7244bbac0200012d5a5b03a06bbcb891054ae72e64e2d9a3e46077fecf8d2d6af4496771671d910000000001e72d286979ee6cb1b7e65dfddfb2e384100b8d148e7758de42e4168b71792c60a0490100000000008e7778b7ff900a0b82779d0d768cb63b11dcd685014140c54d9d6148503a45de3c037aa6c08ccede953246bdac680a9e9f4ca2414cb02ee130c9a246771191df6bda8796f01f432bfaa464f331137d75865d0c3310f4dc2321036f97d99a1fa298e82ab6ccdedd6febd72fa5b3fa415e09f47354f3cecec51f07acd101530800ba1dd20500000014e31c39cf87027016bf0b925cb6db0699e41d235514bd12389c3eede155f28d6f72c44cb70756aff3f253c1087472616e7366657267fb1c540417067c270dee32f21023aa8b9b71abce0000000000000000000191c12f3ad7a6dc3b8c9cfb6e47d5adb94ef31e76b8dbac538a20a103ba11931f000001e72d286979ee6cb1b7e65dfddfb2e384100b8d148e7758de42e4168b71792c600100000000000000bd12389c3eede155f28d6f72c44cb70756aff3f201414026034a105f0a694f0320b617f112eea7b21a268c54d383e8964e9045e970b8bcc020c3c12e99d560657f2f5874d0a508748bf362bccb0d15f0c9a2c22641ceba2321036200e224b07b5f88b934e36933e5c31826d3b2dc9a5a0a72a555cd5fd70feda5acd1015308803b081117000000141be8765dcb5600ac58a6cc9be39f8d5734c4f1d3148cba604700afc229870ec93ae4f2c25e78f95c4f53c1087472616e7366657267fb1c540417067c270dee32f21023aa8b9b71abce00000000000000000001d4d309fddde1101278ec53443cabb902cbbb2330ce4a16b0876c7f2c411990b5000001e72d286979ee6cb1b7e65dfddfb2e384100b8d148e7758de42e4168b71792c6001000000000000008cba604700afc229870ec93ae4f2c25e78f95c4f01414057755879205922936aef9d641f7ac2fd59a9605c01ae5e2cf730ededcc59ef60eaf5d1a5f150c5bd33c3c78b86e441d4d464856bf30ca7b9d89f5299c86d3d7e23210237965fbbff6457d897a9763d6bf97c8f700735e938fa21236aa23e648e641494ac02000109992fadaed0cf0609e42d5fea6fc5057a340893b756c19d73bd0ed92109a0a00000000001e72d286979ee6cb1b7e65dfddfb2e384100b8d148e7758de42e4168b71792c606027000000000000fa1f3b71b6332c5880e1b2808f86e3bf730fbdec0141409ee7a22eee8a502ea3bdd264ba81f36cf7360332456fae92f50d4d89c06cbeda083c61562af8c279e91e490bbabc2e4bee481d85887ff5a36f8dbb26d1308fa22321036980dc27f23a7e3c0ea0fe50f66f6b37a7d21ffaa66d5571ce6d4d317e22a5e7ac80000001cba3499f1640f91f7074593e632d18224e5ca94054c63a72cc3c208fe76a65960100019b7cffdaa674beae0f930ebe6085af9093e5fe56b34a5c220ccdcf6efc336fc500aaa0680b0000007c2f0bc324085be8b5dcf68bc8ed142620b18d850141406020880ded8ae65e6b8af680882f4c3e702cb41f9dcd8a898ea69a32077d05a0503df9d70ff1e71a400dd9a7a2222df9ab348e6cd501473b05add04fb028f960232102f4830c08c254e6e81839396c44c039639f1e30b6e53878269b567d9253590aacac" + rawtx := "0000000005440c786a66aaebf472aacb1d1db19d5b494c6a9226ea91bf5cf0e63a6605138cde5064efb81bc6539620b9e6d6d7c74f97d415b922c4fb4bb1833ce6a97a9d61f962fb7301000065f000005d12ac6c589d59f92e82d8bf60659cb716ffc1f101fd4a010c4011ff5d2138cf546d112ef712ee8a15277f7b6f1d5d2564b97497ac155782e6089cd3005dc9de81a8b22bb2f1c3a2edbac55e01581cb27980fdedf3a8bc57fa470c40657253c374a48da773fc653591f282a63a60695f29ab6c86300020ed505a019e5563e1be493efa71bdde37b16b4ec3f5f6dc2d2a2550151b020176b4dbe7afe40c403efdc559cb6bff135fd79138267db897c6fded01e3a0f15c0fb1c337359935d65e7ac49239f020951a74a96e11e73d225c9789953ffec40d5f7c9a84707b1d9a0c402804f24ab8034fa41223977ba48883eb94951184e31e5739872daf4f65461de3196ebf333f6d7dc4aff0b7b2143793179415f50a715484aba4e33b97dc636e150c40ed6b2ffeaef97eef746815ad16f5b8aed743892e93f7216bb744eb5c2f4cad91ae291919b61cd9a8d50fe85630d5e010c49a01ed687727c3ae5a7e17d4da213afdfd00150c2103009b7540e10f2562e5fd8fac9eaec25166a58b26e412348ff5a86927bfac22a20c21030205e9cefaea5a1dfc580af20c8d5aa2468bb0148f1a5e4605fc622c80e604ba0c210214baf0ceea3a66f17e7e1e839ea25fd8bed6cd82e6bb6e68250189065f44ff010c2103408dcd416396f64783ac587ea1e1593c57d9fea880c8a6a1920e92a2594778060c2102a7834be9b32e2981d157cb5bbd3acb42cfd11ea5c3b10224d7a44e98c5910f1b0c2102ba2c70f5996f357a43198705859fae2cfea13e1172962800772b3d588a9d4abd0c2102f889ecd43c5126ff1932d75fa87dea34fc95325fb724db93c8f79fe32cc3f180170b41138defaf0202c1353ed4e94d0cbc00be80024f7673890000000000261c130000000000e404210001f813c2cc8e18bbe4b3b87f8ef9105b50bb93918e01005d0300743ba40b0000000c14aa07cc3f2193a973904a09a6e60b87f1f96273970c14f813c2cc8e18bbe4b3b87f8ef9105b50bb93918e13c00c087472616e736665720c14bcaf41d684c7d4ad6ee0d99da9707b9d1f0c8e6641627d5b523801420c402360bbf64b9644c25f066dbd406454b07ab9f56e8e25d92d90c96c598f6c29d97eabdcf226f3575481662cfcdd064ee410978e5fae3f09a2f83129ba9cd82641290c2103caf763f91d3691cba5b5df3eb13e668fdace0295b37e2e259fd0fb152d354f900b4195440d78" rawtxBytes, _ := hex.DecodeString(rawtx) - b := Block{} + b := New(netmode.TestNet) - assert.NoError(t, testserdes.DecodeBinary(rawtxBytes, &b)) - expected := map[string]bool{ // 18 trans - - "009f61f481f47eb7478e887871e4e744669d461b13d68e04250035260171d706": false, - "3a62e473c1d67ac561b98e8131f7f7ceded4cd250edb78a6814ec9915930ad93": false, - "d56a545d2f9400c09d5aa4e8cc37cc994d5a6892f9c30de95ff69a3b647b27a2": false, - "57f6baa9cb23ce9117d66aee7c31ba6d1e82e140a805db1c5992ada849f6a7c7": false, - "f700be9c723ed44900ac9d70874b9d8601033bb78883c0a43ab38b5d96c09c11": false, - "31674ac8553b371ddf06db6a3aef09b8d6f37da03a8cc2868b71044c54ef0034": false, - "44858de48ec97cea2f823128e9d58981dde11f28a6ebf0a2cb745ea13223dd71": false, - "317f3ff3768b2aebe3d4866f6e0e8b875cc7937a1b8b5f91be066dc51ed61be2": false, - "8c24f44f1533567c71e722f49bc7a4d9b323a09e2950fd975291817578119508": false, - "55a7a738aaee8f7e6d7bcd4c8a38813e57763bff8bfb296418b6cac6d5bfb89a": false, - "dfa5f84366cf0b48f1b1e9b24a73557e657f6ac21b676528401f5a630aece571": false, - "5839fbcbbca68aef41dfa9a371222565519626affad6be0977d38a82259480a5": false, - "6873568cae35e4ce0a7d07ef080ef6eb699b2b9dcbc419fad1c4f645ff8579fc": false, - "dbb3c0688003bede7e7bc56d2c9d6362b594512ac686820739d963ef91e2eb9e": false, - "3d12353cb8bae8be928131580e960a82f37ca3ad6957ad22c8cadc1b21b2dd1a": false, - "8ca87fd5843f000939244151ce027bad5c1f30f1867c7054918b7f9a66b949e8": false, - "ad088940e45a73e00a3cdb7f3248c67a3f6e5d1f05d4cfd44c4e1f4d26cfef87": false, - "908a398dd65dfd2aad6c06090c5a71d5e5280746577a6ddd5a1f2c1453f71ead": false, + assert.NoError(t, testserdes.DecodeBinary(rawtxBytes, b)) + expected := map[string]bool{ // 1 trans + "58ea0709dac398c451fd51fdf4466f5257c77927c7909834a0ef3b469cd1a2ce": false, } var hashes []string for _, tx := range b.Transactions { - switch tx.Type { - case transaction.ContractType: - hashes = append(hashes, tx.Hash().StringLE()) - case transaction.MinerType: - hashes = append(hashes, tx.Hash().StringLE()) - case transaction.ClaimType: - hashes = append(hashes, tx.Hash().StringLE()) - case transaction.InvocationType: - hashes = append(hashes, tx.Hash().StringLE()) - } + hashes = append(hashes, tx.Hash().StringLE()) } assert.Equal(t, len(expected), len(hashes)) @@ -171,56 +153,35 @@ func TestBinBlockDecodeEncode(t *testing.T) { } assert.Equal(t, true, val) - data, err := testserdes.EncodeBinary(&b) + data, err := testserdes.EncodeBinary(b) assert.NoError(t, err) assert.Equal(t, rawtx, hex.EncodeToString(data)) - testserdes.MarshalUnmarshalJSON(t, &b, new(Block)) + testserdes.MarshalUnmarshalJSON(t, b, New(netmode.TestNet)) } func TestBlockSizeCalculation(t *testing.T) { - // block taken from mainnet: 0006d3ff96e269f599eb1b5c5a527c218439e498dcc65b63794591bbcdc0516b + // block taken from testnet at height 61451: b2d9f9fe9860ff71a45c5278e2a84c22bdda84dd8e9313f1e440bea955ea540d // The Size in golang is given by counting the number of bytes of an object. (len(Bytes)) // its implementation is different from the corresponding C# and python implementations. But the result should // should be the same.In this test we provide more details then necessary because in case of failure we can easily debug the // root cause of the size calculation missmatch. - rawBlock := "00000000ba33df12e8adbf38b6039e79ee91fdb8b1519e2e6154cb59c0653c81769288f4a22492109b7a84077ed7226c28612eb61428ea9ded9bdc952cdfc13deb4172ef85d1115b0bb62300abff35093d19a14a59e75d652b5d3827bf04c165bbe9ef95cca4bf5501fd45014012afae6df64195041e4764b57caa9e27fc2cfc596833163904136ec95816d104b44b3737d0e9f6b1b4445cd3b6a5cc80f6b0935675bc44dba44415eb309832b3404dc95bcf85e4635556a1d618e4ce947b26972992ed74788df5f9501b850ac0b40b7112d1ff30e4ade00369e16f0d13932d1ba76725e7682db072f8e2cd7752b840d12bb7dd45dd3b0e2098db5c67b6de55b7c40164937491fcaca1239b25860251224ead23ab232add78ccccd347239eae50ffc98f50b2a84c60ec5c3d284647a7406fabf6ca241b759af6b71080c0dfad7395632e989226a7e52f8cd2c133aeb2226e6e1aea47666fd81f578405a9f9bbd9d0bc523c3a44d7a5099ddc649feabe5f406188b8ee478731a89beeb76fdbd108eb0071b8f2b8678f40c5a1f387a491314336783255dee8cc5af4bf914dfeaacecc318fc13e02262658e39e8ce0631941b1f1552102486fd15702c4490a26703112a5cc1d0923fd697a33406bd5a1c00e0013b09a7021024c7b7fb6c310fccf1ba33b082519d82964ea93868d676662d4a59ad548df0e7d2102aaec38470f6aad0042c6e877cfd8087d2676b0f516fddd362801b9bd3936399e2103b209fd4f53a7170ea4444e0cb0a6bb6a53c2bd016926989cf85f9b0fba17a70c2103b8d9d5771d8f513aa0869b9cc8d50986403b78c6da36890638c3d46a5adce04a2102ca0e27697b9c248f6f16e085fd0061e26f44da85b58ee835c110caa5ec3ba5542102df48f60e8f3e01c48ff40b9b7f1310d7a8b2a193188befe1c2e3df740e89509357ae140000abff350900000000d101530800e1f5050000000014d8dd86f6d91eb2add2f2d8afeda2184ed94ac33314288017f85d80b889fe02beb5ff203ed9ef538f1653c1087472616e7366657267cf9472821400ceb06ca780c2a937fec5bbec51b900000000000000000220288017f85d80b889fe02beb5ff203ed9ef538f16f0153135323738393433373039313963623362646632650000014140b61b1a8d220c28633fa1a43ef02d334731b16013778664bc28db838d9ab8cfa64f9134fe952ad8a8eb8a6dd9d864055301bcdba4177fd6ee0f52b3f096db2fe4232102bca5c56af0f11e7042f5eaf3d8b2767feb3a8e3ba5668b00e6ea21cb7a215689ac8000000177de54907d16326ff29c3fcd4892afae32043e87ca844929157857093632c4010000019b7cffdaa674beae0f930ebe6085af9093e5fe56b34a5c220ccdcf6efc336fc500e9a435000000000849ee84e1f3daaf226589c05de2bf8bcae8c94001414092ba4569663dacd95921318658f8f40662bcff61fdcbbe08da0938a6c93a6d1075b76c86fa5454ca41f762d3b955b8d6755b79ccaf52754169b69e8904f166f8232102e019359f675526fc8505198647e31ed3044ccb0e5cc2ea22fb3bed5420cdf687ac800001ff076e656f2d6f6e6501f3617958f115913192d1de50c8c5ac2c411a4177c7801554d2bf69c27dac86c7010002e72d286979ee6cb1b7e65dfddfb2e384100b8d148e7758de42e4168b71792c606400000000000000915fe29d2d3847bce516f31fcd33f0fb1d90573be72d286979ee6cb1b7e65dfddfb2e384100b8d148e7758de42e4168b71792c6034ed1a0000000000c85c8dca1fbb7473522109cecaf3acac2e27afc60141406a5ad8c2b6e3783184703d22f3bee39a8b0b6f81477bff61833090361cd52ca5160d66215e6044c31aaed44304a28273c65c9ba736cc75341b45fb18995a6c922321039eae6f12690848807983df6accc1b2929de8582e772be6b3ac084a02a576272eacd10187084d3198000000000008660ceb7bc700000014b3a766ac60afa2990d9251db08138fd1facf07ed0800e3598f01000000209b7cffdaa674beae0f930ebe6085af9093e5fe56b34a5c220ccdcf6efc336fc514e420bbe1e5bcdfa1b43e97a57380a6cd8fddfd4c56c1096d616b654f6666657267bd097b2fcf70e1fd30a5c3ef51e662feeafeba0100000000000000000120e420bbe1e5bcdfa1b43e97a57380a6cd8fddfd4c01659c1aa6f2f42f7d0548a9680df197d4dda767434490e8bed3e25dbbac5206cd000001e72d286979ee6cb1b7e65dfddfb2e384100b8d148e7758de42e4168b71792c6001000000000000007335f929546270b8f811a0f9427b5712457107e70241400f871fcc8bb58d110ea7b1a4c34390542a925203b147bd68137c9edc79044a657cd5dc00514270d65a77a97c814d1f5090054b6c35f1cde698f765538ccf290c2321023056f0a219758bcd503ff4123a589962003331cb9e14168d649ae7426e3ec26eac4140a4036b311b31e0620fcde6e83ed29e6c7e7fcadf59dcac1ccae352a83608c8117dcd36ca64d5a2ce041b2274481ce65b6d30b463d1ca87a0269177d034ad218d232102a1e6ed9a5cff73ad33b7896465af8e9206eab9c8c75502868b783deb64f232eaacd10179207dcc40f47af5b26c52342d5292eb741b7beaa0d58a9a4a1563441fd0f40c30e1349b7cffdaa674beae0f930ebe6085af9093e5fe56b34a5c220ccdcf6efc336fc5b3a766ac60afa2990d9251db08138fd1facf07ed52c10b63616e63656c4f6666657267bd097b2fcf70e1fd30a5c3ef51e662feeafeba01000000000000000001202e5596a5c23eff8907aa180201c5a6f53c041dd101a9822ade57f6f9b6e999be06961af808137f3c9051b6c674bcc9e8aec8c1b6f1000001e72d286979ee6cb1b7e65dfddfb2e384100b8d148e7758de42e4168b71792c6001000000000000007335f929546270b8f811a0f9427b5712457107e7024140b5b58794f8c4f2493a2cff25aa7546a79b6f9e1f279911b2d15a07926084705aeaf64d18454f40feda8ddb9096745eb2e16a208320e9122007fac350892cb3d823210308ec2156f3366339c54c59e4c0342888665abdd76ccbd6b2020961225ccfa3f4ac41404f947ca69b7a2ec0926989f30f3d3d986d488b7c01270eee56326b2f0be856353448062a5d2d73ce34bfdacec3af42b082f1c5186fc063b38c321c1a1eb37157232102a1e6ed9a5cff73ad33b7896465af8e9206eab9c8c75502868b783deb64f232eaacd101792084e25c75cef1e92d39333408dae6e31799d6316b2d908aa094d0dc18f137484c349b7cffdaa674beae0f930ebe6085af9093e5fe56b34a5c220ccdcf6efc336fc5b3a766ac60afa2990d9251db08138fd1facf07ed52c10b63616e63656c4f6666657267bd097b2fcf70e1fd30a5c3ef51e662feeafeba01000000000000000001202e5596a5c23eff8907aa180201c5a6f53c041dd101ead2059c2cf4101cb02a1dae5875dc993189d047a84f05c080318779453b3c0e000001e72d286979ee6cb1b7e65dfddfb2e384100b8d148e7758de42e4168b71792c6001000000000000007335f929546270b8f811a0f9427b5712457107e7024140c4c924181d2b1516467f20fd3cf4b75ce5dd75d916318b77cd9ebd4bf9a3fb3bef47151adb01e0828bc127db6859f11890f86bc5bae2980cba5fcefba0d7edf523210308ec2156f3366339c54c59e4c0342888665abdd76ccbd6b2020961225ccfa3f4ac41407beaabc59bbc4db241aca812b624befcc595d3f8299e996a7d660decd3cb162afc6d810d5e3001aae5874c42b7031b1445f8562c209a2e2726ca1316dffd8867232102a1e6ed9a5cff73ad33b7896465af8e9206eab9c8c75502868b783deb64f232eaacd101530800e1f5050000000014d8dd86f6d91eb2add2f2d8afeda2184ed94ac33314288017f85d80b889fe02beb5ff203ed9ef538f1653c1087472616e7366657267f91d6b7085db7c5aaf09f19eeec1ca3c0db2c6ec00000000000000000220288017f85d80b889fe02beb5ff203ed9ef538f16f015313532373839343337373637356464383030353031000001414061609a0460a3ccfe1a9cb5db9f75811e08d52328f291a1b848ec607718be0a37206a90e3a81908c4b71ec859b684e493c088e640b2e2d471bd370aae50bdf160232102bca5c56af0f11e7042f5eaf3d8b2767feb3a8e3ba5668b00e6ea21cb7a215689ac80000001128218ba3c40a03066c862b0eaad5c06a39a1ae653e08f69e70f528ec4e18dc60500019b7cffdaa674beae0f930ebe6085af9093e5fe56b34a5c220ccdcf6efc336fc500a3e11100000000db2395d79fbd27d7b93b62cccd0fe0afc15ff80b0141404d953b03a1f53911fb1524a9f12126790e5e8468c05ed24ac3f71b881623510fcbe2f5497a4e8d1f1d1748774b9b3487be5f45dbd91bfb697a27ae2d2f2d9bb32321030ab39b99d8675cd9bd90aaec37cba964297cc817078d33e508ab11f1d245c068acd101792017a323cf2b0c650243be29d1b2c3ca69c141fdd7d72a36242c225f175c818a46349b7cffdaa674beae0f930ebe6085af9093e5fe56b34a5c220ccdcf6efc336fc5b3a766ac60afa2990d9251db08138fd1facf07ed52c10b63616e63656c4f6666657267bd097b2fcf70e1fd30a5c3ef51e662feeafeba01000000000000000001202e5596a5c23eff8907aa180201c5a6f53c041dd1010a190ead75c8235b2db69d9eb00040209ce719c3450d90bca893bcfcdbe5e58c000001e72d286979ee6cb1b7e65dfddfb2e384100b8d148e7758de42e4168b71792c6001000000000000007335f929546270b8f811a0f9427b5712457107e7024140b1dbd06a250ee76dc773e7efc915caea48732ca10f813d1027073dbba57032752c0ac7ed30fdb8b18df0abaf5831bd86e444785445253099b46c271676c4a16423210308ec2156f3366339c54c59e4c0342888665abdd76ccbd6b2020961225ccfa3f4ac4140a3b256ac1dd57de358bc1a45b632b3dd41f07d4c6d6e9ffe33fd0cf7c44e29673100bc8a8760727b46bf96642d6dd4a9c4edf657fb2a27b83f564a5b91408ad9232102a1e6ed9a5cff73ad33b7896465af8e9206eab9c8c75502868b783deb64f232eaacd1014e03a0860114d023de91710f63a0259e8d95d1f6563e1572783c14b18f53a903d7873b1453a748c3f80787eca2e30f53c1087472616e7366657267187fc13bec8ff0906c079e7f4cc8276709472913000000000000000004fee36e656f2d6f6e652d696e766f6b653a7b22636f6e7472616374223a22307831333239343730393637323763383463376639653037366339306630386665633362633137663138222c226d6574686f64223a227472616e73666572222c22706172616d73223a5b5b2266726f6d222c22307830666533613265633837303766386333343861373533313433623837643730336139353338666231225d2c5b22746f222c22307833633738373231353365353666366431393538643965323561303633306637313931646532336430225d2c5b2276616c7565222c22302e303031225d5d7dff076e656f2d6f6e65ff0a3233313635343031383420b18f53a903d7873b1453a748c3f80787eca2e30f0000014140910c4b3be37fe09052215f99ef546342c21ded22ef862c165ff0da3ff1087274d0fafb5bbac25aa927dc477b239df732d95afe782a46caeaca669ae096659f13232102c2dbc83931d5e550b95ceab8a94c6af37735fe2aa4e9fb217bce46001937b2f1acd1014e03a0860114de33c5d07f933c0f90da952cdfe2677d3f9a24d714f26e3a75379dc20c8642f3f11e20af76b12065f453c1087472616e7366657267aa67d0447c61bdddc4d1690d2269d772f9c37795000000000000000004fee36e656f2d6f6e652d696e766f6b653a7b22636f6e7472616374223a22307839353737633366393732643736393232306436396431633464646264363137633434643036376161222c226d6574686f64223a227472616e73666572222c22706172616d73223a5b5b2266726f6d222c22307866343635323062313736616632303165663166333432383630636332396433373735336136656632225d2c5b22746f222c22307864373234396133663764363765326466326339356461393030663363393337666430633533336465225d2c5b2276616c7565222c22302e303031225d5d7dff076e656f2d6f6e65ff0933363133393630393120f26e3a75379dc20c8642f3f11e20af76b12065f40000014140b1630c1546547df4b69fdf6c68fcbf9a3f1de2787d0ea7237aea639ab0a227a092147e47194595c0d960df0d209773da32808da767c15730926bcf844ed12f702321021a9f5ed87fe58e7a366c20975d4112698e4c0ccb3ba9cbce0400a482ecf99b67acd1014e03a08601148ba89ee5ab5c4975e0e12f88a8ce4aa8928108c9145e5c739e5d4b5a29af596c2cc162f1facded25fe53c1087472616e7366657267952d12a025325e56a4cb3ba2d469b1e23c7c77a0000000000000000004fee36e656f2d6f6e652d696e766f6b653a7b22636f6e7472616374223a22307861303737376333636532623136396434613233626362613435363565333232356130313232643935222c226d6574686f64223a227472616e73666572222c22706172616d73223a5b5b2266726f6d222c22307866653235656463646661663136326331326336633539616632393561346235643965373335633565225d2c5b22746f222c22307863393038383139326138346163656138383832666531653037353439356361626535396561383862225d2c5b2276616c7565222c22302e303031225d5d7dff076e656f2d6f6e65ff0a33383237333138333238205e5c739e5d4b5a29af596c2cc162f1facded25fe000001414050f556b29417eb44b66b283a72ff33b697f49b2b6d1520eb4fe5a9974632c1b1586b3e7f0aafac4707d65f89daa86592c8ad98c78016769a5de904330d02d2ed23210201008fe0ffcdab73b598c89c6ae2b46d90de38287abd7dd50a325d0bfb2469d5acd1014e03a086011444d65fda3f2062502c03c2bfd85c700a0d046fae149d12fcef2c830d73a570e9b89857962fcf3a619a53c1087472616e7366657267187fc13bec8ff0906c079e7f4cc8276709472913000000000000000004fee36e656f2d6f6e652d696e766f6b653a7b22636f6e7472616374223a22307831333239343730393637323763383463376639653037366339306630386665633362633137663138222c226d6574686f64223a227472616e73666572222c22706172616d73223a5b5b2266726f6d222c22307839613631336163663266393635373938623865393730613537333064383332636566666331323964225d2c5b22746f222c22307861653666303430643061373035636438626663323033326335303632323033666461356664363434225d2c5b2276616c7565222c22302e303031225d5d7dff076e656f2d6f6e65ff0a31353931373638373437209d12fcef2c830d73a570e9b89857962fcf3a619a00000141409ec506aab7045da733d02c8c9ebaa615d9aa02fa8c4d8eb35ad08a3b4843167cdd059094f492f77e68efa2b66d87305e13b3f08a326cf4b3dadaa29aaa64b30a23210275699ef1532219ee8e9d2d8a75b6b96b7cb4d5f9788391de31daceebed9ac8edacd1014e03a086011444bb85601b2d8c5247a1999dfb18ee7928e10cdf1479ed35e989051c8f2404b869c17ce75912de78b953c1087472616e7366657267aa67d0447c61bdddc4d1690d2269d772f9c37795000000000000000004fee36e656f2d6f6e652d696e766f6b653a7b22636f6e7472616374223a22307839353737633366393732643736393232306436396431633464646264363137633434643036376161222c226d6574686f64223a227472616e73666572222c22706172616d73223a5b5b2266726f6d222c22307862393738646531323539653737636331363962383034323438663163303538396539333565643739225d2c5b22746f222c22307864663063653132383739656531386662396439396131343735323863326431623630383562623434225d2c5b2276616c7565222c22302e303031225d5d7dff076e656f2d6f6e65ff0a333738313933373030382079ed35e989051c8f2404b869c17ce75912de78b9000001414081a2d21af431df3345478836ae24dc7714ce647daa1daac3a99ed17645a8c86a981d86c5d2280af45259a1cf4a85c115ecbe8ff5a398c0bea23c218c0c8c26f02321020be10b4bddffe752a7cfaa16d1718ce6da460608ca41ad9bf7ff66dc5f60c860acd10179201322db68df23cee8da600e7cf5875a8d919bf8e318bbe7afbcd1fdbd5758d67b349b7cffdaa674beae0f930ebe6085af9093e5fe56b34a5c220ccdcf6efc336fc5b3a766ac60afa2990d9251db08138fd1facf07ed52c10b63616e63656c4f6666657267bd097b2fcf70e1fd30a5c3ef51e662feeafeba01000000000000000001202e5596a5c23eff8907aa180201c5a6f53c041dd10181c3670591e333a19a14aae556d211f3490163380c1f28ef55b0bb0e4a8aec1a000001e72d286979ee6cb1b7e65dfddfb2e384100b8d148e7758de42e4168b71792c6001000000000000007335f929546270b8f811a0f9427b5712457107e7024140dd2aa6075329f43375655c83b04d343974fb13908888fa6b242b599c789c1cf635b530b6834093332720f93d185b450884951acfb261aec61fe9057efbdeb4b523210308ec2156f3366339c54c59e4c0342888665abdd76ccbd6b2020961225ccfa3f4ac4140f152dc9454ebf518bc0ab8192543add5844ad7007177986a3dd038db313740ea72abb5d49866caa4d470d75182a7e715fd2b9a6e345ef2568bf82e92878743db232102a1e6ed9a5cff73ad33b7896465af8e9206eab9c8c75502868b783deb64f232eaac8000000198f4ec54f46fd86c0955accb7bda7ff06ffc10c45651206fbcbfeabe78c597750000019b7cffdaa674beae0f930ebe6085af9093e5fe56b34a5c220ccdcf6efc336fc500e40b54020000002fb7e583c973498fef06f317a9762507e7ac0306014140c4a7388365a4e8a93e2229fd617805902773a8ef7354e95487819eec59379a6a8fb045ed126025db151336e2393eaf75dd524f1ebe872f92185f8d1a6a71a6a5232102b37eaec8631a5bb8579d4ba268e2fbc9c81b555f08558bba6eccb9d1448332c5ac02000155810e77f1dd89622915f3fceb051ac8abeaa2e7ea7a2c38e0744137c3c8982b0000000001e72d286979ee6cb1b7e65dfddfb2e384100b8d148e7758de42e4168b71792c605e1502000000000024fdf844d637cf5a60a9744f1ab8ab8d6f2c18cf0141407dafb244fceee305d477892a21ca8cbd31906fbcc233e0bfccd0fe91d4f6dafdd067f7301cd3e8c7c6197f71615df4b7cedb987eb3ebff79ad729bb8768e1e50232102f8a4a73deefad4c114039b854cc4e974c409f30720e2567d15dea2204b8c45f7acd1012000c108776974686472617769bd097b2fcf70e1fd30a5c3ef51e662feeafeba01000000000000000003a15100000000000000000000000000000000000000000000000000000000000000a232e125258b7db0a0dffde5bd03b2b859253538ab000000000000000000000000a48098c835c493eb3b1967e44150630cc6435e564e00000000000000000000000001dfeee6c60db6403b5538e86120f01e60dcea749c73ce36b9058f050be8b7d2c9000001e72d286979ee6cb1b7e65dfddfb2e384100b8d148e7758de42e4168b71792c600100000000000000bd097b2fcf70e1fd30a5c3ef51e662feeafeba010102000000d101530800e1f5050000000014d8dd86f6d91eb2add2f2d8afeda2184ed94ac33314288017f85d80b889fe02beb5ff203ed9ef538f1653c1087472616e7366657267f56c89be8bfcdec617e2402b5c3fd5b6d71b820d00000000000000000220288017f85d80b889fe02beb5ff203ed9ef538f16f0153135323738393433383433393264623331653662630000014140654af3a0cc69faa3dd42ff76c4012aa9c72e269bba004d6e910f195e33b2ecae980be4531a3677f27d3c90f4196632790997078bca4f8471c6db43b55928c3ef232102bca5c56af0f11e7042f5eaf3d8b2767feb3a8e3ba5668b00e6ea21cb7a215689ac" + rawBlock := "0000000005440c786a66aaebf472aacb1d1db19d5b494c6a9226ea91bf5cf0e63a6605138cde5064efb81bc6539620b9e6d6d7c74f97d415b922c4fb4bb1833ce6a97a9d61f962fb7301000065f000005d12ac6c589d59f92e82d8bf60659cb716ffc1f101fd4a010c4011ff5d2138cf546d112ef712ee8a15277f7b6f1d5d2564b97497ac155782e6089cd3005dc9de81a8b22bb2f1c3a2edbac55e01581cb27980fdedf3a8bc57fa470c40657253c374a48da773fc653591f282a63a60695f29ab6c86300020ed505a019e5563e1be493efa71bdde37b16b4ec3f5f6dc2d2a2550151b020176b4dbe7afe40c403efdc559cb6bff135fd79138267db897c6fded01e3a0f15c0fb1c337359935d65e7ac49239f020951a74a96e11e73d225c9789953ffec40d5f7c9a84707b1d9a0c402804f24ab8034fa41223977ba48883eb94951184e31e5739872daf4f65461de3196ebf333f6d7dc4aff0b7b2143793179415f50a715484aba4e33b97dc636e150c40ed6b2ffeaef97eef746815ad16f5b8aed743892e93f7216bb744eb5c2f4cad91ae291919b61cd9a8d50fe85630d5e010c49a01ed687727c3ae5a7e17d4da213afdfd00150c2103009b7540e10f2562e5fd8fac9eaec25166a58b26e412348ff5a86927bfac22a20c21030205e9cefaea5a1dfc580af20c8d5aa2468bb0148f1a5e4605fc622c80e604ba0c210214baf0ceea3a66f17e7e1e839ea25fd8bed6cd82e6bb6e68250189065f44ff010c2103408dcd416396f64783ac587ea1e1593c57d9fea880c8a6a1920e92a2594778060c2102a7834be9b32e2981d157cb5bbd3acb42cfd11ea5c3b10224d7a44e98c5910f1b0c2102ba2c70f5996f357a43198705859fae2cfea13e1172962800772b3d588a9d4abd0c2102f889ecd43c5126ff1932d75fa87dea34fc95325fb724db93c8f79fe32cc3f180170b41138defaf0202c1353ed4e94d0cbc00be80024f7673890000000000261c130000000000e404210001f813c2cc8e18bbe4b3b87f8ef9105b50bb93918e01005d0300743ba40b0000000c14aa07cc3f2193a973904a09a6e60b87f1f96273970c14f813c2cc8e18bbe4b3b87f8ef9105b50bb93918e13c00c087472616e736665720c14bcaf41d684c7d4ad6ee0d99da9707b9d1f0c8e6641627d5b523801420c402360bbf64b9644c25f066dbd406454b07ab9f56e8e25d92d90c96c598f6c29d97eabdcf226f3575481662cfcdd064ee410978e5fae3f09a2f83129ba9cd82641290c2103caf763f91d3691cba5b5df3eb13e668fdace0295b37e2e259fd0fb152d354f900b4195440d78" rawBlockBytes, _ := hex.DecodeString(rawBlock) - b := Block{} - assert.NoError(t, testserdes.DecodeBinary(rawBlockBytes, &b)) + b := New(netmode.TestNet) + assert.NoError(t, testserdes.DecodeBinary(rawBlockBytes, b)) expected := []struct { ID string - Type string Size int Version int - InputsLen int - OutputsLen int + SignersLen int AttributesLen int WitnessesLen int - }{ // 20 trans - {ID: "f59b04d8e6526684b94b5f8cdbdf691feaff5d45e9aa8e2325a668f1b9130786", Type: "MinerTransaction", Size: 10, Version: 0, InputsLen: 0, OutputsLen: 0, AttributesLen: 0, WitnessesLen: 0}, - {ID: "7463345f771e70019185d72fa5bd00fbb4f26735daae398ecc6540419332d81e", Type: "InvocationTransaction", Size: 244, Version: 1, InputsLen: 0, OutputsLen: 0, AttributesLen: 2, WitnessesLen: 1}, - {ID: "cf3aeda21d320ec9b49d322f2b88fea21aa7e9bf243c1e02dfe08f5cc82b74b0", Type: "ContractTransaction", Size: 202, Version: 0, InputsLen: 1, OutputsLen: 1, AttributesLen: 0, WitnessesLen: 1}, - {ID: "07e502d13ae6255cfabbc9ee2f78a48fc1c43a4f7f713f128342db721bc01af5", Type: "ContractTransaction", Size: 271, Version: 0, InputsLen: 1, OutputsLen: 2, AttributesLen: 1, WitnessesLen: 1}, - {ID: "0de0baf53136c188bdd179fed9530dfb7dd80697fd59e47ffe294db4f421eb67", Type: "InvocationTransaction", Size: 469, Version: 1, InputsLen: 1, OutputsLen: 1, AttributesLen: 1, WitnessesLen: 2}, - {ID: "233c8b00ab6a43aafae7fcc2be47fc46493185bb3376160b5809cb745aee3329", Type: "InvocationTransaction", Size: 455, Version: 1, InputsLen: 1, OutputsLen: 1, AttributesLen: 1, WitnessesLen: 2}, - {ID: "8bf3ae0c692fc830753029fcb6575625ea8181b444cffcbe38404a28b77b3856", Type: "InvocationTransaction", Size: 455, Version: 1, InputsLen: 1, OutputsLen: 1, AttributesLen: 1, WitnessesLen: 2}, - {ID: "c5285e1460191e1ca7fc07e3c26c5facebb033d56b63b7a41ebf11f2a1cb4306", Type: "InvocationTransaction", Size: 244, Version: 1, InputsLen: 0, OutputsLen: 0, AttributesLen: 2, WitnessesLen: 1}, - {ID: "dce8b5f6dc093a910e405a230e9b7d546688d411cf960c8a1cc7d386d89b56d6", Type: "ContractTransaction", Size: 202, Version: 0, InputsLen: 1, OutputsLen: 1, AttributesLen: 0, WitnessesLen: 1}, - {ID: "4cce087cadfa99c2adeaaf1916ada025db124cef8f05d4535b0ad8047ef7d29e", Type: "InvocationTransaction", Size: 455, Version: 1, InputsLen: 1, OutputsLen: 1, AttributesLen: 1, WitnessesLen: 2}, - {ID: "67df57a20c9d3b2942925f2c66fdc15a21be2c229a22122f6acbdac4dd10bf0a", Type: "InvocationTransaction", Size: 466, Version: 1, InputsLen: 0, OutputsLen: 0, AttributesLen: 4, WitnessesLen: 1}, - {ID: "ad51030b30e016293caed92781b3bb3f993f86c15ab1153582f658d603fe23db", Type: "InvocationTransaction", Size: 465, Version: 1, InputsLen: 0, OutputsLen: 0, AttributesLen: 4, WitnessesLen: 1}, - {ID: "1db2d62ad3530f1ae6ca7bd95e766beaff97058681f0e203d8744d7bba065012", Type: "InvocationTransaction", Size: 466, Version: 1, InputsLen: 0, OutputsLen: 0, AttributesLen: 4, WitnessesLen: 1}, - {ID: "7d7bb6f0db6a71aca85fc9267fa6a59654b00b5f778a39c27214c68f11950f61", Type: "InvocationTransaction", Size: 466, Version: 1, InputsLen: 0, OutputsLen: 0, AttributesLen: 4, WitnessesLen: 1}, - {ID: "1d534dcf1ce63a9ea9328eab309891ea2a0a5cb11e95cabf22860ee1fb649521", Type: "InvocationTransaction", Size: 466, Version: 1, InputsLen: 0, OutputsLen: 0, AttributesLen: 4, WitnessesLen: 1}, - {ID: "8f4c9089871a4ad0076b27c061395079e0862f685f27e4bc01b7bac67b0cf8d0", Type: "InvocationTransaction", Size: 455, Version: 1, InputsLen: 1, OutputsLen: 1, AttributesLen: 1, WitnessesLen: 2}, - {ID: "52b4653fca02e8042092456490036f0b9b18b339f65d9c334e7e9d2b4599f8db", Type: "ContractTransaction", Size: 202, Version: 0, InputsLen: 1, OutputsLen: 1, AttributesLen: 0, WitnessesLen: 1}, - {ID: "2b4854b1f46c9af0eb06587fd375355adfeea3c8f5921295421251af93d737e1", Type: "ClaimTransaction", Size: 203, Version: 0, InputsLen: 0, OutputsLen: 1, AttributesLen: 0, WitnessesLen: 1}, - {ID: "61e95e5b14625e897423670dfc3babf021d6b99ca2a73203dd1ac2604a2daadf", Type: "InvocationTransaction", Size: 244, Version: 1, InputsLen: 1, OutputsLen: 1, AttributesLen: 3, WitnessesLen: 1}, - {ID: "b361dfec8c2cde980b340d2c3ec63cecaea634f91b6d76f24a586aa60fbde483", Type: "InvocationTransaction", Size: 244, Version: 1, InputsLen: 0, OutputsLen: 0, AttributesLen: 2, WitnessesLen: 1}, + }{ // 1 trans + {ID: "58ea0709dac398c451fd51fdf4466f5257c77927c7909834a0ef3b469cd1a2ce", Size: 252, Version: 0, SignersLen: 1, AttributesLen: 0, WitnessesLen: 1}, } for i, tx := range b.Transactions { @@ -228,10 +189,8 @@ func TestBlockSizeCalculation(t *testing.T) { assert.Equal(t, expected[i].ID, txID.StringLE()) assert.Equal(t, expected[i].Size, io.GetVarSize(tx)) - assert.Equal(t, expected[i].Type, tx.Type.String()) assert.Equal(t, expected[i].Version, int(tx.Version)) - assert.Equal(t, expected[i].InputsLen, len(tx.Inputs)) - assert.Equal(t, expected[i].OutputsLen, len(tx.Outputs)) + assert.Equal(t, expected[i].SignersLen, len(tx.Signers)) assert.Equal(t, expected[i].AttributesLen, len(tx.Attributes)) assert.Equal(t, expected[i].WitnessesLen, len(tx.Scripts)) } @@ -240,25 +199,24 @@ func TestBlockSizeCalculation(t *testing.T) { // Block specific tests assert.Equal(t, 0, int(b.Version)) - assert.Equal(t, "f4889276813c65c059cb54612e9e51b1b8fd91ee799e03b638bfade812df33ba", b.PrevHash.StringLE()) - assert.Equal(t, "ef7241eb3dc1df2c95dc9bed9dea2814b62e61286c22d77e07847a9b109224a2", b.MerkleRoot.StringLE()) - assert.Equal(t, 1527894405, int(b.Timestamp)) - assert.Equal(t, 2340363, int(b.Index)) + assert.Equal(t, "1305663ae6f05cbf91ea26926a4c495b9db11d1dcbaa72f4ebaa666a780c4405", b.PrevHash.StringLE()) + assert.Equal(t, "9d7aa9e63c83b14bfbc422b915d4974fc7d7d6e6b9209653c61bb8ef6450de8c", b.MerkleRoot.StringLE()) + assert.Equal(t, 1597650434401, int(b.Timestamp)) + assert.Equal(t, 61541, int(b.Index)) nextConsensus := address.Uint160ToString(b.NextConsensus) - assert.Equal(t, "APyEx5f4Zm4oCHwFWiSTaph1fPBxZacYVR", nextConsensus) + assert.Equal(t, "NUQ6Q4BWvHU71HNxPQ4LMSHPMK1jSz1nw4", nextConsensus) - assert.Equal(t, "4012afae6df64195041e4764b57caa9e27fc2cfc596833163904136ec95816d104b44b3737d0e9f6b1b4445cd3b6a5cc80f6b0935675bc44dba44415eb309832b3404dc95bcf85e4635556a1d618e4ce947b26972992ed74788df5f9501b850ac0b40b7112d1ff30e4ade00369e16f0d13932d1ba76725e7682db072f8e2cd7752b840d12bb7dd45dd3b0e2098db5c67b6de55b7c40164937491fcaca1239b25860251224ead23ab232add78ccccd347239eae50ffc98f50b2a84c60ec5c3d284647a7406fabf6ca241b759af6b71080c0dfad7395632e989226a7e52f8cd2c133aeb2226e6e1aea47666fd81f578405a9f9bbd9d0bc523c3a44d7a5099ddc649feabe5f406188b8ee478731a89beeb76fdbd108eb0071b8f2b8678f40c5a1f387a491314336783255dee8cc5af4bf914dfeaacecc318fc13e02262658e39e8ce0631941b1", hex.EncodeToString(b.Script.InvocationScript)) - assert.Equal(t, "552102486fd15702c4490a26703112a5cc1d0923fd697a33406bd5a1c00e0013b09a7021024c7b7fb6c310fccf1ba33b082519d82964ea93868d676662d4a59ad548df0e7d2102aaec38470f6aad0042c6e877cfd8087d2676b0f516fddd362801b9bd3936399e2103b209fd4f53a7170ea4444e0cb0a6bb6a53c2bd016926989cf85f9b0fba17a70c2103b8d9d5771d8f513aa0869b9cc8d50986403b78c6da36890638c3d46a5adce04a2102ca0e27697b9c248f6f16e085fd0061e26f44da85b58ee835c110caa5ec3ba5542102df48f60e8f3e01c48ff40b9b7f1310d7a8b2a193188befe1c2e3df740e89509357ae", hex.EncodeToString(b.Script.VerificationScript)) - assert.Equal(t, "0006d3ff96e269f599eb1b5c5a527c218439e498dcc65b63794591bbcdc0516b", b.Hash().StringLE()) + assert.Equal(t, "DEAR/10hOM9UbREu9xLuihUnf3tvHV0lZLl0l6wVV4LmCJzTAF3J3oGosiuy8cOi7brFXgFYHLJ5gP3t86i8V/pHDEBlclPDdKSNp3P8ZTWR8oKmOmBpXymrbIYwACDtUFoBnlVj4b5JPvpxvd43sWtOw/X23C0qJVAVGwIBdrTb56/kDEA+/cVZy2v/E1/XkTgmfbiXxv3tAeOg8VwPscM3NZk11l56xJI58CCVGnSpbhHnPSJcl4mVP/7EDV98moRwex2aDEAoBPJKuANPpBIjl3ukiIPrlJURhOMeVzmHLa9PZUYd4xluvzM/bX3Er/C3shQ3kxeUFfUKcVSEq6TjO5fcY24VDEDtay/+rvl+73RoFa0W9biu10OJLpP3IWu3ROtcL0ytka4pGRm2HNmo1Q/oVjDV4BDEmgHtaHcnw65afhfU2iE6", base64.StdEncoding.EncodeToString(b.Script.InvocationScript)) + assert.Equal(t, "FQwhAwCbdUDhDyVi5f2PrJ6uwlFmpYsm5BI0j/WoaSe/rCKiDCEDAgXpzvrqWh38WAryDI1aokaLsBSPGl5GBfxiLIDmBLoMIQIUuvDO6jpm8X5+HoOeol/YvtbNgua7bmglAYkGX0T/AQwhA0CNzUFjlvZHg6xYfqHhWTxX2f6ogMimoZIOkqJZR3gGDCECp4NL6bMuKYHRV8tbvTrLQs/RHqXDsQIk16ROmMWRDxsMIQK6LHD1mW81ekMZhwWFn64s/qE+EXKWKAB3Kz1Yip1KvQwhAviJ7NQ8USb/GTLXX6h96jT8lTJftyTbk8j3n+Msw/GAFwtBE43vrw==", base64.StdEncoding.EncodeToString(b.Script.VerificationScript)) + assert.Equal(t, "b2d9f9fe9860ff71a45c5278e2a84c22bdda84dd8e9313f1e440bea955ea540d", b.Hash().StringLE()) - benc, err := testserdes.EncodeBinary(&b) + benc, err := testserdes.EncodeBinary(b) assert.NoError(t, err) // test size of the block - assert.Equal(t, 7360, len(benc)) + assert.Equal(t, 952, len(benc)) assert.Equal(t, rawBlock, hex.EncodeToString(benc)) } -*/ func TestBlockCompare(t *testing.T) { b1 := Block{Base: Base{Index: 1}} diff --git a/pkg/core/block/helper_test.go b/pkg/core/block/helper_test.go index cede76763..98f1abf23 100644 --- a/pkg/core/block/helper_test.go +++ b/pkg/core/block/helper_test.go @@ -7,6 +7,7 @@ import ( "io/ioutil" "testing" + "github.com/nspcc-dev/neo-go/pkg/config/netmode" "github.com/nspcc-dev/neo-go/pkg/internal/testserdes" "github.com/stretchr/testify/require" ) @@ -18,7 +19,7 @@ func getDecodedBlock(t *testing.T, i int) *Block { b, err := hex.DecodeString(data["raw"].(string)) require.NoError(t, err) - block := &Block{} + block := New(netmode.TestNet) require.NoError(t, testserdes.DecodeBinary(b, block)) return block diff --git a/pkg/core/test_data/block_1.json b/pkg/core/test_data/block_1.json index dd73c3591..80743cb87 100644 --- a/pkg/core/test_data/block_1.json +++ b/pkg/core/test_data/block_1.json @@ -1,33 +1,49 @@ { - "raw": "00000000bf4421c88776c53b43ce1dc45463bfd2028e322fdfb60064be150ed3e36125d418f98ec3ed2c2d1c9427385e7b85d0d1a366e29c4e399693a59718380f8bbad6d6d90358010000004490d0bb7170726c59e75d652b5d3827bf04c165bbe9ef95cca4bf5501fd4501404edf5005771de04619235d5a4c7a9a11bb78e008541f1da7725f654c33380a3c87e2959a025da706d7255cb3a3fa07ebe9c6559d0d9e6213c68049168eb1056f4038a338f879930c8adc168983f60aae6f8542365d844f004976346b70fb0dd31aa1dbd4abd81e4a4aeef9941ecd4e2dd2c1a5b05e1cc74454d0403edaee6d7a4d4099d33c0b889bf6f3e6d87ab1b11140282e9a3265b0b9b918d6020b2c62d5a040c7e0c2c7c1dae3af9b19b178c71552ebd0b596e401c175067c70ea75717c8c00404e0ebd369e81093866fe29406dbf6b402c003774541799d08bf9bb0fc6070ec0f6bad908ab95f05fa64e682b485800b3c12102a8596e6c715ec76f4564d5eff34070e0521979fcd2cbbfa1456d97cc18d9b4a6ad87a97a2a0bcdedbf71b6c9676c645886056821b6f3fec8694894c66f41b762bc4e29e46ad15aee47f05d27d822f1552102486fd15702c4490a26703112a5cc1d0923fd697a33406bd5a1c00e0013b09a7021024c7b7fb6c310fccf1ba33b082519d82964ea93868d676662d4a59ad548df0e7d2102aaec38470f6aad0042c6e877cfd8087d2676b0f516fddd362801b9bd3936399e2103b209fd4f53a7170ea4444e0cb0a6bb6a53c2bd016926989cf85f9b0fba17a70c2103b8d9d5771d8f513aa0869b9cc8d50986403b78c6da36890638c3d46a5adce04a2102ca0e27697b9c248f6f16e085fd0061e26f44da85b58ee835c110caa5ec3ba5542102df48f60e8f3e01c48ff40b9b7f1310d7a8b2a193188befe1c2e3df740e89509357ae0100004490d0bb00000000", - "hash": "d782db8a38b0eea0d7394e0f007c61c71798867578c77c387c08113903946cc9", - "size": 686, + "raw": "000000002c343609ae0055bcdb57cc6e89b8e466cb264522feb1e0f916eb4a6a0d50f6a9129f211ef3bddbb1ed3ac496d6ee2de537764c4fb26c4b470e2f3a52fe6474dd75de3eb973010000c8000000e0a3c55cad72028fb5901748b19a27be21f6540401fd4a010c40d9bd422d752b9703080dd03c0b7182578d393e28f64ada3b76211f7b939c74a835bf354608af0ce8569ed9a65a7c578f1bbb742563c3086539e8b5ad5a0900590c405125cd7e76c2ce97546b9e5ea74ab313fb5875dc6d0567102ca2efee14e1de8d2b1deb332101b7c703d9c051ea6d43230db5fc787941bb40ad2c327a491936c10c402ad062631f244303d5818be9bce3d8aa5384ffaf8c531181166f45a230f96f93f42ea1c24286fe90e683249b39233223d84fe0996dcb458ef1288607ead535a50c40da40c40953d461d34014c5e66859874f6eec0740373054ea57dd66f615e2fa03fa395222b502f54210c0914975839c472702454e8d18040b702e6443f7e84f020c40393978243b8e81c6e08f0b021b9795c1c8f8d4d6155f0f16e28f30715bc38798a98b82d98e02a47f84d8b441ba157e8b280d27024fa1159e861c45fab9a647befdfd00150c2103009b7540e10f2562e5fd8fac9eaec25166a58b26e412348ff5a86927bfac22a20c21030205e9cefaea5a1dfc580af20c8d5aa2468bb0148f1a5e4605fc622c80e604ba0c210214baf0ceea3a66f17e7e1e839ea25fd8bed6cd82e6bb6e68250189065f44ff010c21023e9b32ea89b94d066e649b124fd50e396ee91369e8e2a6ae1b11c170d022256d0c2103408dcd416396f64783ac587ea1e1593c57d9fea880c8a6a1920e92a2594778060c2102a7834be9b32e2981d157cb5bbd3acb42cfd11ea5c3b10224d7a44e98c5910f1b0c2102ba2c70f5996f357a43198705859fae2cfea13e1172962800772b3d588a9d4abd170b41138defaf02045be5c3458d87a02c00f5f0617fc6ab5b000000000016f51200000000004615200001574d3c03df4a9b2772af08e4b296721009b7a6fd0100530c2102a7834be9b32e2981d157cb5bbd3acb42cfd11ea5c3b10224d7a44e98c5910f1b11c00c11726567697374657243616e6469646174650c1425059ecb4878d3a875f91c51ceded330d4575fde41627d5b5201420c40e3dfd02f6ec79dd6dbbe434540349187d975d5931bcf961c9d6b463d97165437049beec702ee14e69eb953c785134e689a3108464a130147174a80421756f391290c2102a7834be9b32e2981d157cb5bbd3acb42cfd11ea5c3b10224d7a44e98c5910f1b0b4195440d78", + "hash": "0xfe767cae1a0a2c0825cc3610dd5fccd6b0dac4a5e2ab56644eea53cafce64848", + "size": 942, "version": 0, - "previousblockhash": "d42561e3d30e15be6400b6df2f328e02d2bf6354c41dce433bc57687c82144bf", - "merkleroot": "d6ba8b0f381897a59396394e9ce266a3d1d0857b5e3827941c2d2cedc38ef918", - "time": 1476647382, - "index": 1, - "nonce": "6c727071bbd09044", - "nextconsensus": "APyEx5f4Zm4oCHwFWiSTaph1fPBxZacYVR", - "script": { - "invocation": "404edf5005771de04619235d5a4c7a9a11bb78e008541f1da7725f654c33380a3c87e2959a025da706d7255cb3a3fa07ebe9c6559d0d9e6213c68049168eb1056f4038a338f879930c8adc168983f60aae6f8542365d844f004976346b70fb0dd31aa1dbd4abd81e4a4aeef9941ecd4e2dd2c1a5b05e1cc74454d0403edaee6d7a4d4099d33c0b889bf6f3e6d87ab1b11140282e9a3265b0b9b918d6020b2c62d5a040c7e0c2c7c1dae3af9b19b178c71552ebd0b596e401c175067c70ea75717c8c00404e0ebd369e81093866fe29406dbf6b402c003774541799d08bf9bb0fc6070ec0f6bad908ab95f05fa64e682b485800b3c12102a8596e6c715ec76f4564d5eff34070e0521979fcd2cbbfa1456d97cc18d9b4a6ad87a97a2a0bcdedbf71b6c9676c645886056821b6f3fec8694894c66f41b762bc4e29e46ad15aee47f05d27d822", - "verification": "552102486fd15702c4490a26703112a5cc1d0923fd697a33406bd5a1c00e0013b09a7021024c7b7fb6c310fccf1ba33b082519d82964ea93868d676662d4a59ad548df0e7d2102aaec38470f6aad0042c6e877cfd8087d2676b0f516fddd362801b9bd3936399e2103b209fd4f53a7170ea4444e0cb0a6bb6a53c2bd016926989cf85f9b0fba17a70c2103b8d9d5771d8f513aa0869b9cc8d50986403b78c6da36890638c3d46a5adce04a2102ca0e27697b9c248f6f16e085fd0061e26f44da85b58ee835c110caa5ec3ba5542102df48f60e8f3e01c48ff40b9b7f1310d7a8b2a193188befe1c2e3df740e89509357ae" + "previousblockhash": "0xa9f6500d6a4aeb16f9e0b1fe224526cb66e4b8896ecc57dbbc5500ae0936342c", + "merkleroot": "0xdd7464fe523a2f0e474b6cb24f4c7637e52deed696c43aedb1dbbdf31e219f12", + "time": 1596540771957, + "index": 200, + "nextconsensus": "NgPkjjLTNcQad99iRYeXRUuowE4gxLAnDL", + "witnesses": [ + { + "invocation": "DEDZvUItdSuXAwgN0DwLcYJXjTk+KPZK2jt2IR97k5x0qDW/NUYIrwzoVp7Zplp8V48bu3QlY8MIZTnota1aCQBZDEBRJc1+dsLOl1Rrnl6nSrMT+1h13G0FZxAsou/uFOHejSsd6zMhAbfHA9nAUeptQyMNtfx4eUG7QK0sMnpJGTbBDEAq0GJjHyRDA9WBi+m849iqU4T/r4xTEYEWb0WiMPlvk/QuocJChv6Q5oMkmzkjMiPYT+CZbctFjvEohgfq1TWlDEDaQMQJU9Rh00AUxeZoWYdPbuwHQDcwVOpX3Wb2FeL6A/o5UiK1AvVCEMCRSXWDnEcnAkVOjRgEC3AuZEP36E8CDEA5OXgkO46BxuCPCwIbl5XByPjU1hVfDxbijzBxW8OHmKmLgtmOAqR/hNi0QboVfosoDScCT6EVnoYcRfq5pke+", + "verification": "FQwhAwCbdUDhDyVi5f2PrJ6uwlFmpYsm5BI0j/WoaSe/rCKiDCEDAgXpzvrqWh38WAryDI1aokaLsBSPGl5GBfxiLIDmBLoMIQIUuvDO6jpm8X5+HoOeol/YvtbNgua7bmglAYkGX0T/AQwhAj6bMuqJuU0GbmSbEk/VDjlu6RNp6OKmrhsRwXDQIiVtDCEDQI3NQWOW9keDrFh+oeFZPFfZ/qiAyKahkg6SollHeAYMIQKng0vpsy4pgdFXy1u9OstCz9EepcOxAiTXpE6YxZEPGwwhAroscPWZbzV6QxmHBYWfriz+oT4RcpYoAHcrPViKnUq9FwtBE43vrw==" + } + ], + "consensusdata": { + "primary": 4, + "nonce": "2ca0878d45c3e55b" }, "tx": [ { - "txid": "d6ba8b0f381897a59396394e9ce266a3d1d0857b5e3827941c2d2cedc38ef918", - "size": 10, - "type": "MinerTransaction", + "hash": "0xca3e47909a27096ee880fac3b1f261dc912b0ba04c83f9142692cfefccedd41a", + "size": 242, "version": 0, + "nonce": 2137125109, + "sender": "NTsaVneGBcARqEddHLAYaS6bncsZNS6X3S", + "sysfee": "6007750", + "netfee": "1242390", + "validuntilblock": 2102598, + "signers": [ + { + "account": "0xfda6b709107296b2e408af72279b4adf033c4d57", + "scopes": "CalledByEntry" + } + ], "attributes": [], - "vin": [], - "vout": [], - "sysfee": "0", - "netfee": "0", - "witnesses": [], - "nonce": 3151007812 + "script": "DCECp4NL6bMuKYHRV8tbvTrLQs/RHqXDsQIk16ROmMWRDxsRwAwRcmVnaXN0ZXJDYW5kaWRhdGUMFCUFnstIeNOodfkcUc7e0zDUV1/eQWJ9W1I=", + "witnesses": [ + { + "invocation": "DEDj39Avbsed1tu+Q0VANJGH2XXVkxvPlhyda0Y9lxZUNwSb7scC7hTmnrlTx4UTTmiaMQhGShMBRxdKgEIXVvOR", + "verification": "DCECp4NL6bMuKYHRV8tbvTrLQs/RHqXDsQIk16ROmMWRDxsLQZVEDXg=" + } + ] } ], - "confirmations": 2020977, - "nextblockhash": "bf638e92c85016df9bc3b62b33f3879fa22d49d5f55d822b423149a3bca9e574" -} + "confirmations": 67197, + "nextblockhash": "0x99b23a3bb26cae7e78b880a8b6bacf85a7ae923c7d6239f9a9f72604909fbba3" +} \ No newline at end of file diff --git a/pkg/core/test_data/block_2.json b/pkg/core/test_data/block_2.json index ad9c00a5d..e038837b2 100644 --- a/pkg/core/test_data/block_2.json +++ b/pkg/core/test_data/block_2.json @@ -1,33 +1,24 @@ { - "raw": "00000000c96c94033911087c387cc77875869817c7617c000f4e39d7a0eeb0388adb82d74208df9542f56a42fb2764142d13274c951087c609565fd5c4ab9b57a183a1afead9035802000000b66fa838e89c9ab259e75d652b5d3827bf04c165bbe9ef95cca4bf5501fd450140e8a85159d8655c7b5a66429831eb15dabefc0f27a22bef67febb9eccb6859cc4c5c6ae675175a0bbefeeeeff2a8e9f175aaaae0796f3b5f29cb93b5b50fbf270409270a02cbbcb99969d6dc8a85708d5609dc1bba9569c849b53db7896c7f1ffd3adc789c0fe8400fb665478567448b4c4bd9c1657432591e4de83df10348f865a40724a9cf9d43eda558bfa8755e7bd1c0e9282f96164f4ff0b7369fd80e878cf49f2e61ed0fdf8cf218e7fdd471be5f29ef1242c39f3695d5decb169667fe0d3d140860da333249f7c54db09b548ad5d5e45fb8787238d51b35a6d4759f7990f47f00ff102e7b88f45acce423dd9f4b87dbf85e7e2c5c7a6aace11e62267c0bbe16b4028d272a701c22c5f8aa3495fa22d7d5a583518ef552e73813ee369c6d51ad2f246a24eb0092ebe7e1550d7de2ee09abad4dae4f4c0277317f5b1190041b9c2c2f1552102486fd15702c4490a26703112a5cc1d0923fd697a33406bd5a1c00e0013b09a7021024c7b7fb6c310fccf1ba33b082519d82964ea93868d676662d4a59ad548df0e7d2102aaec38470f6aad0042c6e877cfd8087d2676b0f516fddd362801b9bd3936399e2103b209fd4f53a7170ea4444e0cb0a6bb6a53c2bd016926989cf85f9b0fba17a70c2103b8d9d5771d8f513aa0869b9cc8d50986403b78c6da36890638c3d46a5adce04a2102ca0e27697b9c248f6f16e085fd0061e26f44da85b58ee835c110caa5ec3ba5542102df48f60e8f3e01c48ff40b9b7f1310d7a8b2a193188befe1c2e3df740e89509357ae010000b66fa83800000000", - "hash": "0xbf638e92c85016df9bc3b62b33f3879fa22d49d5f55d822b423149a3bca9e574", - "size": 686, + "raw": "00000000f791a09cffc085e7864d56ad8a74ee3e04f43c9affcbf14a87a903a889e8e215b5ef5b1df95f0fa5fe508157abdc64680a850dfb36018406758f02da97fc6ced5fccc5da73010000b88800005d12ac6c589d59f92e82d8bf60659cb716ffc1f101fd4a010c40fecf3fed562e1d39cfbc198b4bd5ccdfcea48b300917f3fb45c6f67004bfce8f816198018ccc93a595d62c1030eb29de56380ca67c087dadf4fd73e7f2ef2b910c409b6f623a720fabf6c21dc6e45f0a408a61b3664a81c08a644440b760884db2578fc00e0a16ac0c5bcb441713c0eb56b8448e6fe11c874cc78340ff62350e56f50c40b069d11b240c193fbbbb8115771827a133ca43e03d85ed0ce51893e1ea8ad9c779e8f683f1f455f57518c97a892fdfad7806364a11a9fb349b668a97862c503e0c4027fbc2eca5271da68905deee04ce3cd67450cf52c80c0ffea6d13c68708f3ba3ff6d4312bfff4d096ed5533342c5cf408c4130d05bfd0487dccb025a4b43c0fd0c408bbd56726fb88e4cf4f8dd33a57f9ab6297c8d84de210a585aaacb74cc00746daf44ea6e713d33c2e87344baec2f3cf70c72513d3bd5c7071c5c7d434c828c11fdfd00150c2103009b7540e10f2562e5fd8fac9eaec25166a58b26e412348ff5a86927bfac22a20c21030205e9cefaea5a1dfc580af20c8d5aa2468bb0148f1a5e4605fc622c80e604ba0c210214baf0ceea3a66f17e7e1e839ea25fd8bed6cd82e6bb6e68250189065f44ff010c2103408dcd416396f64783ac587ea1e1593c57d9fea880c8a6a1920e92a2594778060c2102a7834be9b32e2981d157cb5bbd3acb42cfd11ea5c3b10224d7a44e98c5910f1b0c2102ba2c70f5996f357a43198705859fae2cfea13e1172962800772b3d588a9d4abd0c2102f889ecd43c5126ff1932d75fa87dea34fc95325fb724db93c8f79fe32cc3f180170b41138defaf01001a82894d04b16977", + "hash": "0xc39ffd0da100be6e8bd1ae536c8cb0b53f9988b635aca58ede3bdc3b6c832d78", + "size": 700, "version": 0, - "previousblockhash": "0xd782db8a38b0eea0d7394e0f007c61c71798867578c77c387c08113903946cc9", - "merkleroot": "0xafa183a1579babc4d55f5609c68710954c27132d146427fb426af54295df0842", - "time": 1476647402, - "index": 2, - "nonce": "b29a9ce838a86fb6", - "nextconsensus": "APyEx5f4Zm4oCHwFWiSTaph1fPBxZacYVR", - "script": { - "invocation": "40e8a85159d8655c7b5a66429831eb15dabefc0f27a22bef67febb9eccb6859cc4c5c6ae675175a0bbefeeeeff2a8e9f175aaaae0796f3b5f29cb93b5b50fbf270409270a02cbbcb99969d6dc8a85708d5609dc1bba9569c849b53db7896c7f1ffd3adc789c0fe8400fb665478567448b4c4bd9c1657432591e4de83df10348f865a40724a9cf9d43eda558bfa8755e7bd1c0e9282f96164f4ff0b7369fd80e878cf49f2e61ed0fdf8cf218e7fdd471be5f29ef1242c39f3695d5decb169667fe0d3d140860da333249f7c54db09b548ad5d5e45fb8787238d51b35a6d4759f7990f47f00ff102e7b88f45acce423dd9f4b87dbf85e7e2c5c7a6aace11e62267c0bbe16b4028d272a701c22c5f8aa3495fa22d7d5a583518ef552e73813ee369c6d51ad2f246a24eb0092ebe7e1550d7de2ee09abad4dae4f4c0277317f5b1190041b9c2c2", - "verification": "552102486fd15702c4490a26703112a5cc1d0923fd697a33406bd5a1c00e0013b09a7021024c7b7fb6c310fccf1ba33b082519d82964ea93868d676662d4a59ad548df0e7d2102aaec38470f6aad0042c6e877cfd8087d2676b0f516fddd362801b9bd3936399e2103b209fd4f53a7170ea4444e0cb0a6bb6a53c2bd016926989cf85f9b0fba17a70c2103b8d9d5771d8f513aa0869b9cc8d50986403b78c6da36890638c3d46a5adce04a2102ca0e27697b9c248f6f16e085fd0061e26f44da85b58ee835c110caa5ec3ba5542102df48f60e8f3e01c48ff40b9b7f1310d7a8b2a193188befe1c2e3df740e89509357ae" - }, - "tx": [ + "previousblockhash": "0x15e2e889a803a9874af1cbff9a3cf4043eee748aad564d86e785c0ff9ca091f7", + "merkleroot": "0xed6cfc97da028f7506840136fb0d850a6864dcab578150fea50f5ff91d5befb5", + "time": 1597103262815, + "index": 35000, + "nextconsensus": "NUQ6Q4BWvHU71HNxPQ4LMSHPMK1jSz1nw4", + "witnesses": [ { - "txid": "0xafa183a1579babc4d55f5609c68710954c27132d146427fb426af54295df0842", - "size": 10, - "type": "MinerTransaction", - "version": 0, - "attributes": [], - "vin": [], - "vout": [], - "sysfee": "0", - "netfee": "0", - "witnesses": [], - "nonce": 950562742 + "invocation": "DED+zz/tVi4dOc+8GYtL1czfzqSLMAkX8/tFxvZwBL/Oj4FhmAGMzJOlldYsEDDrKd5WOAymfAh9rfT9c+fy7yuRDECbb2I6cg+r9sIdxuRfCkCKYbNmSoHAimREQLdgiE2yV4/ADgoWrAxby0QXE8DrVrhEjm/hHIdMx4NA/2I1Dlb1DECwadEbJAwZP7u7gRV3GCehM8pD4D2F7QzlGJPh6orZx3no9oPx9FX1dRjJeokv3614BjZKEan7NJtmipeGLFA+DEAn+8LspScdpokF3u4EzjzWdFDPUsgMD/6m0TxocI87o/9tQxK//00JbtVTM0LFz0CMQTDQW/0Eh9zLAlpLQ8D9DECLvVZyb7iOTPT43TOlf5q2KXyNhN4hClhaqst0zAB0ba9E6m5xPTPC6HNEuuwvPPcMclE9O9XHBxxcfUNMgowR", + "verification": "FQwhAwCbdUDhDyVi5f2PrJ6uwlFmpYsm5BI0j/WoaSe/rCKiDCEDAgXpzvrqWh38WAryDI1aokaLsBSPGl5GBfxiLIDmBLoMIQIUuvDO6jpm8X5+HoOeol/YvtbNgua7bmglAYkGX0T/AQwhA0CNzUFjlvZHg6xYfqHhWTxX2f6ogMimoZIOkqJZR3gGDCECp4NL6bMuKYHRV8tbvTrLQs/RHqXDsQIk16ROmMWRDxsMIQK6LHD1mW81ekMZhwWFn64s/qE+EXKWKAB3Kz1Yip1KvQwhAviJ7NQ8USb/GTLXX6h96jT8lTJftyTbk8j3n+Msw/GAFwtBE43vrw==" } ], - "confirmations": 2021026, - "nextblockhash": "0x1fca8800f1ffbc9fb08bcfee1269461161d58dcee0252cf4db13220ba8189c5d" -} + "consensusdata": { + "primary": 0, + "nonce": "7769b1044d89821a" + }, + "tx": [], + "confirmations": 32432, + "nextblockhash": "0x03bac24218cbee1326d1d3bfd7e18c96dd1cfa7f45d66ddf67f2523fc273b2aa" +} \ No newline at end of file From 04bff62d65c4e9db8e3f356671d7a291b1272447 Mon Sep 17 00:00:00 2001 From: Evgenii Stratonikov Date: Tue, 18 Aug 2020 15:09:30 +0300 Subject: [PATCH 2/4] transaction: update binary test data --- pkg/core/transaction/helper_test.go | 7 ++--- pkg/core/transaction/transaction_test.go | 35 ++++++++++++------------ 2 files changed, 21 insertions(+), 21 deletions(-) diff --git a/pkg/core/transaction/helper_test.go b/pkg/core/transaction/helper_test.go index cdfba61ff..072dee52a 100644 --- a/pkg/core/transaction/helper_test.go +++ b/pkg/core/transaction/helper_test.go @@ -9,15 +9,14 @@ import ( ) var ( - //TODO NEO3.0: Update binary - // https://neotracker.io/tx/fe4b3af60677204c57e573a57bdc97bc5059b05ad85b1474f84431f88d910f64 - rawInvocationTX = "d101590400b33f7114839c33710da24cf8e7d536b8d244f3991cf565c8146063795d3b9b3cd55aef026eae992b91063db0db53c1087472616e7366657267c5cc1cb5392019e2cc4e6d6b5ea54c8d4b6d11acf166cb072961424c54f6000000000000000001206063795d3b9b3cd55aef026eae992b91063db0db0000014140c6a131c55ca38995402dff8e92ac55d89cbed4b98dfebbcb01acbc01bd78fa2ce2061be921b8999a9ab79c2958875bccfafe7ce1bbbaf1f56580815ea3a4feed232102d41ddce2c97be4c9aa571b8a32cbc305aa29afffbcae71b0ef568db0e93929aaac" + // tx from testnet 58ea0709dac398c451fd51fdf4466f5257c77927c7909834a0ef3b469cd1a2ce + rawInvocationTX = "00be80024f7673890000000000261c130000000000e404210001f813c2cc8e18bbe4b3b87f8ef9105b50bb93918e01005d0300743ba40b0000000c14aa07cc3f2193a973904a09a6e60b87f1f96273970c14f813c2cc8e18bbe4b3b87f8ef9105b50bb93918e13c00c087472616e736665720c14bcaf41d684c7d4ad6ee0d99da9707b9d1f0c8e6641627d5b523801420c402360bbf64b9644c25f066dbd406454b07ab9f56e8e25d92d90c96c598f6c29d97eabdcf226f3575481662cfcdd064ee410978e5fae3f09a2f83129ba9cd82641290c2103caf763f91d3691cba5b5df3eb13e668fdace0295b37e2e259fd0fb152d354f900b4195440d78" ) func decodeTransaction(rawTX string, t *testing.T) *Transaction { b, err1 := hex.DecodeString(rawTX) assert.Nil(t, err1) - tx, err := NewTransactionFromBytes(netmode.UnitTestNet, b) + tx, err := NewTransactionFromBytes(netmode.TestNet, b) assert.NoError(t, err) return tx } diff --git a/pkg/core/transaction/transaction_test.go b/pkg/core/transaction/transaction_test.go index 79d0ed7fa..761a07b80 100644 --- a/pkg/core/transaction/transaction_test.go +++ b/pkg/core/transaction/transaction_test.go @@ -1,10 +1,12 @@ package transaction import ( + "encoding/base64" "encoding/hex" "testing" "github.com/nspcc-dev/neo-go/pkg/config/netmode" + "github.com/nspcc-dev/neo-go/pkg/encoding/address" "github.com/nspcc-dev/neo-go/pkg/internal/testserdes" "github.com/nspcc-dev/neo-go/pkg/util" "github.com/stretchr/testify/assert" @@ -34,33 +36,32 @@ func TestWitnessEncodeDecode(t *testing.T) { t.Log(len(witDecode.InvocationScript)) } -// TODO NEO3.0: update binary -/* - func TestDecodeEncodeInvocationTX(t *testing.T) { tx := decodeTransaction(rawInvocationTX, t) - assert.Equal(t, tx.Type, InvocationType) - assert.IsType(t, tx.Data, &InvocationTX{}) - invocTX := tx.Data.(*InvocationTX) - script := "0400b33f7114839c33710da24cf8e7d536b8d244f3991cf565c8146063795d3b9b3cd55aef026eae992b91063db0db53c1087472616e7366657267c5cc1cb5392019e2cc4e6d6b5ea54c8d4b6d11acf166cb072961424c54f6" - assert.Equal(t, script, hex.EncodeToString(invocTX.Script)) - assert.Equal(t, util.Fixed8(0), invocTX.Gas) + script := "AwB0O6QLAAAADBSqB8w/IZOpc5BKCabmC4fx+WJzlwwU+BPCzI4Yu+SzuH+O+RBbULuTkY4TwAwIdHJhbnNmZXIMFLyvQdaEx9StbuDZnalwe50fDI5mQWJ9W1I4" + assert.Equal(t, script, base64.StdEncoding.EncodeToString(tx.Script)) + assert.Equal(t, uint32(1325564094), tx.Nonce) + assert.Equal(t, int64(9007990), tx.SystemFee) + assert.Equal(t, int64(1252390), tx.NetworkFee) + assert.Equal(t, uint32(2163940), tx.ValidUntilBlock) + assert.Equal(t, "58ea0709dac398c451fd51fdf4466f5257c77927c7909834a0ef3b469cd1a2ce", tx.Hash().StringLE()) - assert.Equal(t, 1, len(tx.Attributes)) - assert.Equal(t, 0, len(tx.Inputs)) - assert.Equal(t, 0, len(tx.Outputs)) - invoc := "40c6a131c55ca38995402dff8e92ac55d89cbed4b98dfebbcb01acbc01bd78fa2ce2061be921b8999a9ab79c2958875bccfafe7ce1bbbaf1f56580815ea3a4feed" - verif := "2102d41ddce2c97be4c9aa571b8a32cbc305aa29afffbcae71b0ef568db0e93929aaac" + assert.Equal(t, 1, len(tx.Signers)) + assert.Equal(t, CalledByEntry, tx.Signers[0].Scopes) + assert.Equal(t, "NiXgSLtGUjTRTgp4y9ax7vyJ9UZAjsRDVt", address.Uint160ToString(tx.Signers[0].Account)) + + assert.Equal(t, 0, len(tx.Attributes)) + invoc := "DEAjYLv2S5ZEwl8Gbb1AZFSwern1bo4l2S2QyWxZj2wp2X6r3PIm81dUgWYs/N0GTuQQl45frj8JovgxKbqc2CZB" + verif := "DCEDyvdj+R02kcultd8+sT5mj9rOApWzfi4ln9D7FS01T5ALQZVEDXg=" assert.Equal(t, 1, len(tx.Scripts)) - assert.Equal(t, invoc, hex.EncodeToString(tx.Scripts[0].InvocationScript)) - assert.Equal(t, verif, hex.EncodeToString(tx.Scripts[0].VerificationScript)) + assert.Equal(t, invoc, base64.StdEncoding.EncodeToString(tx.Scripts[0].InvocationScript)) + assert.Equal(t, verif, base64.StdEncoding.EncodeToString(tx.Scripts[0].VerificationScript)) data, err := testserdes.EncodeBinary(tx) assert.NoError(t, err) assert.Equal(t, rawInvocationTX, hex.EncodeToString(data)) } -*/ func TestNew(t *testing.T) { script := []byte{0x51} From 7eadbcb0627f2dfb051a370209b945c7be423b4b Mon Sep 17 00:00:00 2001 From: Evgenii Stratonikov Date: Tue, 18 Aug 2020 15:19:24 +0300 Subject: [PATCH 3/4] consensus: update binary test data --- pkg/consensus/payload_test.go | 18 ++++++++++++++++++ pkg/consensus/recovery_message_test.go | 21 ++++++++++++++------- 2 files changed, 32 insertions(+), 7 deletions(-) diff --git a/pkg/consensus/payload_test.go b/pkg/consensus/payload_test.go index a2e1ee7f7..46ef1b797 100644 --- a/pkg/consensus/payload_test.go +++ b/pkg/consensus/payload_test.go @@ -2,6 +2,7 @@ package consensus import ( "encoding/hex" + gio "io" "math/rand" "testing" @@ -321,3 +322,20 @@ func TestMessageType_String(t *testing.T) { require.Equal(t, "RecoveryRequest", recoveryRequestType.String()) require.Equal(t, "UNKNOWN(0xff)", messageType(0xff).String()) } + +func TestPayload_DecodeFromTestnet(t *testing.T) { + hexDump := "000000005e3c788da53e6669772c408014abab20c9f33d1a38396de645a2d40fb3a8a37c960801000400423000aaf1b1cd5544485412eab6b1af49b57ae83b236595a0918488a9899e540c4e105aee59ed2cef1015f205ff1909312acab39d504d68f141c77e10ae21e14971ce01420c4040cfd9a6d6aa245d79a905864551dcc68e108c40231b7df8178663ae453f62388c9bd6bf10b1f1fb1a8736faba5561a886efa78ea5ff4f98812a9d2adba5f1f5290c2102a7834be9b32e2981d157cb5bbd3acb42cfd11ea5c3b10224d7a44e98c5910f1b0b4195440d78" + data, err := hex.DecodeString(hexDump) + require.NoError(t, err) + + buf := io.NewBinReaderFromBuf(data) + p := NewPayload(netmode.TestNet) + p.DecodeBinary(buf) + require.NoError(t, buf.Err) + require.NoError(t, p.decodeData()) + require.Equal(t, payload.CommitType, p.Type()) + require.Equal(t, uint32(67734), p.Height()) + + buf.ReadB() + require.Equal(t, gio.EOF, buf.Err) +} diff --git a/pkg/consensus/recovery_message_test.go b/pkg/consensus/recovery_message_test.go index 54544edb0..c8dedf6c3 100644 --- a/pkg/consensus/recovery_message_test.go +++ b/pkg/consensus/recovery_message_test.go @@ -1,11 +1,15 @@ package consensus import ( + "encoding/hex" + gio "io" "testing" "github.com/nspcc-dev/dbft/crypto" "github.com/nspcc-dev/dbft/payload" + "github.com/nspcc-dev/neo-go/pkg/config/netmode" "github.com/nspcc-dev/neo-go/pkg/crypto/keys" + "github.com/nspcc-dev/neo-go/pkg/io" "github.com/nspcc-dev/neo-go/pkg/util" "github.com/stretchr/testify/require" ) @@ -114,23 +118,26 @@ func TestRecoveryMessage_Setters(t *testing.T) { }) } -//TODO NEO3.0: Update binary -/* -func TestRecoveryMessage_DecodeFromTestnet(t *testing.T) { - hexDump := "00000000924b2fa6728782b6afb94873a377c49f31573005e7f2945beb27158ec2e887300d180000010000000000" + - "fd29024100000120003db64b5e8e4ab7138abe65a3be48d3a3f5d10013ab9ffee489706078714f1ea20161e7ba952fdfd5f543891b1fe053af401bc34e9e3f63c90e3c0d6675d156344b00008e4ab71300000000030000414079946c76007e4297b06b074a20dc1d1d6871c74976f244df81bd03f4158a11dd485ed50fc0cc7c6ad352addd8440c5a55d7b7449650bb200e5e58b1fb8a0390c010041403631a490b17ca4fcfe52ed2e7a4ca4c0d3fcca67e73a1ef071f385db1d37cefa7a2de6e56654788647e9142425c29449b0bbfee5c46a96c4bdc79b23c1f862fc02004140147914878c23a9624a62598cebe2c75fdce80c1e19b5c73aa511630f67d4e5a660c63daad7fcfa9bd944f258f51427cb80730b8beb3015a3c2766325bf291a8e02000000989f8fa676ed07885a46ee08af10e1fa1893ef20fbd557dc3c1a9dc498189d5fceff694dcb2085e4969d90c56433b88fd7ba1caef9363829c70419a5314ac36541404f3ee34e11c521f2e31fee439206474d36951443014354ce81b32bd1787e6a92212737f7f72bee59c403ff74292ebf78c4091081174b5921c148cedcbe7bd585000100acfc8399bda6429c64b5c09885a3e4f1a0629f59125df03be956c00f5bb77616c43e43250e96700f80c42ef3e169e9ff9f906518acf0da17c53563ba41d91ebc41409957436afd1736970d4b5e52b8d845663d6b0335a34cf78ece733c71be876cf30125e9bfea197a607ea6945cef7ef28a74676ec23d14378f7ec23964544b6710014140b634941ecab3a5dd7251f9213bfbcff2021b1e3d966e6800007ea6f0d72ec46d2c04c042800e103091d2f5d184d997a10b890b13bf06b1078a4f1822d722891a232102a7bc55fe8684e0119768d104ba30795bdcc86619e864add26156723ed185cd62ac" +func TestRecoveryMessage_Decode(t *testing.T) { + hexDump := "000000007f5b6094e1281e6bac667f1f871aee755dbe62c012868c718d7709de62135d250d1800000100fd0f024100000120003db64b5e000000008e4ab7138abe65a30133175ebcf3c66ad59ed2c532ca19bbb84cb3802f7dc9b6decde10e117ff6fc3303000041e52280e60c46778876e4c7fdcd262170d906090256ff2ac11d14d45516dd465b5b8f241ff78096ee7280f226df677681bff091884dcd7c4f25cd9a61856ce0bc6a01004136b0b971ef320135f61c11475ff07c5cad04635fc1dad41d346d085646e29e6ff1c5181421a203e5d4b627c6bacdd78a78c9f4cb0a749877ea5a9ed2b02196f17f020041ac5e279927ded591c234391078db55cad2ada58bded974fa2d2751470d0b2f94dddc84ed312f31ee960c884066f778e000f4f05883c74defa75d2a2eb524359c7d020000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000041546d2e34cbbfd0d09b7ce937eec07b402bd597f7bef24938f4a01041f443fb4dd31bebcabdaae3942bb9d549724a152e851bee43ebc5f482ddd9316f2690b48e7d00010000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000415281a6579b875c480d9b3cc9144485d1f898e13405eaf1e4117d83844f1265f81a71998d53fa32d6c3b5249446ac036ecda73b1fe8c1341475fcc4b8d6ba8ec6e20141d775fd1a605173a8ed02084fef903ee043239ca4c76cb658809c6216031437e8f4d5a265550d5934fe386732364d9b49a14baef5a1236d02c557cb394a3a0873c82364f65259a991768a35ba18777f76901e1022f87d71910f4e3e46f161299401f2074d0c" data, err := hex.DecodeString(hexDump) require.NoError(t, err) buf := io.NewBinReaderFromBuf(data) - var p Payload + p := NewPayload(netmode.TestNet) p.DecodeBinary(buf) require.NoError(t, buf.Err) + require.NoError(t, p.decodeData()) + require.Equal(t, payload.RecoveryMessageType, p.Type()) + require.NotNil(t, p.message.payload) + req := p.message.payload.(*recoveryMessage).prepareRequest + require.NotNil(t, req) + require.Equal(t, prepareRequestType, p.message.payload.(*recoveryMessage).prepareRequest.Type) buf.ReadB() require.Equal(t, gio.EOF, buf.Err) } -*/ + func getKeys(t *testing.T, n int) []*privateKey { privs := make([]*privateKey, 0, n) for i := 0; i < n; i++ { From 3677cc0e24763bd8136f2b6b050343e49edd84bf Mon Sep 17 00:00:00 2001 From: Evgenii Stratonikov Date: Tue, 18 Aug 2020 15:27:49 +0300 Subject: [PATCH 4/4] core: update GetTransaction test --- pkg/core/blockchain_test.go | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/pkg/core/blockchain_test.go b/pkg/core/blockchain_test.go index 7f281b012..47954ebd7 100644 --- a/pkg/core/blockchain_test.go +++ b/pkg/core/blockchain_test.go @@ -372,17 +372,27 @@ func TestHasBlock(t *testing.T) { } } -//TODO NEO3.0:Update binary -/* func TestGetTransaction(t *testing.T) { - b1 := getDecodedBlock(t, 1) - block := getDecodedBlock(t, 2) bc := newTestChain(t) + tx1 := transaction.New(netmode.UnitTestNet, []byte{byte(opcode.PUSH1)}, 0) + tx1.Signers = []transaction.Signer{{ + Account: testchain.MultisigScriptHash(), + Scopes: transaction.CalledByEntry, + }} + tx2 := transaction.New(netmode.UnitTestNet, []byte{byte(opcode.PUSH2)}, 0) + tx2.Signers = []transaction.Signer{{ + Account: testchain.MultisigScriptHash(), + Scopes: transaction.CalledByEntry, + }} + require.NoError(t, signTx(bc, tx1, tx2)) + b1 := bc.newBlock(tx1) // Turn verification off, because these blocks are really from some other chain // and can't be verified, but we don't care about that in this test. bc.config.VerifyBlocks = false + bc.config.VerifyTransactions = false assert.Nil(t, bc.AddBlock(b1)) + block := bc.newBlock(tx2) assert.Nil(t, bc.AddBlock(block)) // Test unpersisted and persisted access @@ -391,15 +401,13 @@ func TestGetTransaction(t *testing.T) { require.Nil(t, err) assert.Equal(t, block.Index, height) assert.Equal(t, block.Transactions[0], tx) - assert.Equal(t, 10, io.GetVarSize(tx)) + assert.Equal(t, 467, io.GetVarSize(tx)) assert.Equal(t, 1, io.GetVarSize(tx.Attributes)) - assert.Equal(t, 1, io.GetVarSize(tx.Inputs)) - assert.Equal(t, 1, io.GetVarSize(tx.Outputs)) assert.Equal(t, 1, io.GetVarSize(tx.Scripts)) assert.NoError(t, bc.persist()) } } -*/ + func TestGetClaimable(t *testing.T) { bc := newTestChain(t) defer bc.Close()