Merge pull request #1335 from nspcc-dev/tests/binary

Update binary test data
This commit is contained in:
Roman Khimov 2020-08-19 11:33:47 +03:00 committed by GitHub
commit 6dffd4967a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 183 additions and 184 deletions

View file

@ -2,6 +2,7 @@ package consensus
import ( import (
"encoding/hex" "encoding/hex"
gio "io"
"math/rand" "math/rand"
"testing" "testing"
@ -321,3 +322,20 @@ func TestMessageType_String(t *testing.T) {
require.Equal(t, "RecoveryRequest", recoveryRequestType.String()) require.Equal(t, "RecoveryRequest", recoveryRequestType.String())
require.Equal(t, "UNKNOWN(0xff)", messageType(0xff).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)
}

View file

@ -1,11 +1,15 @@
package consensus package consensus
import ( import (
"encoding/hex"
gio "io"
"testing" "testing"
"github.com/nspcc-dev/dbft/crypto" "github.com/nspcc-dev/dbft/crypto"
"github.com/nspcc-dev/dbft/payload" "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/crypto/keys"
"github.com/nspcc-dev/neo-go/pkg/io"
"github.com/nspcc-dev/neo-go/pkg/util" "github.com/nspcc-dev/neo-go/pkg/util"
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
) )
@ -114,23 +118,26 @@ func TestRecoveryMessage_Setters(t *testing.T) {
}) })
} }
//TODO NEO3.0: Update binary func TestRecoveryMessage_Decode(t *testing.T) {
/* hexDump := "000000007f5b6094e1281e6bac667f1f871aee755dbe62c012868c718d7709de62135d250d1800000100fd0f024100000120003db64b5e000000008e4ab7138abe65a30133175ebcf3c66ad59ed2c532ca19bbb84cb3802f7dc9b6decde10e117ff6fc3303000041e52280e60c46778876e4c7fdcd262170d906090256ff2ac11d14d45516dd465b5b8f241ff78096ee7280f226df677681bff091884dcd7c4f25cd9a61856ce0bc6a01004136b0b971ef320135f61c11475ff07c5cad04635fc1dad41d346d085646e29e6ff1c5181421a203e5d4b627c6bacdd78a78c9f4cb0a749877ea5a9ed2b02196f17f020041ac5e279927ded591c234391078db55cad2ada58bded974fa2d2751470d0b2f94dddc84ed312f31ee960c884066f778e000f4f05883c74defa75d2a2eb524359c7d020000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000041546d2e34cbbfd0d09b7ce937eec07b402bd597f7bef24938f4a01041f443fb4dd31bebcabdaae3942bb9d549724a152e851bee43ebc5f482ddd9316f2690b48e7d00010000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000415281a6579b875c480d9b3cc9144485d1f898e13405eaf1e4117d83844f1265f81a71998d53fa32d6c3b5249446ac036ecda73b1fe8c1341475fcc4b8d6ba8ec6e20141d775fd1a605173a8ed02084fef903ee043239ca4c76cb658809c6216031437e8f4d5a265550d5934fe386732364d9b49a14baef5a1236d02c557cb394a3a0873c82364f65259a991768a35ba18777f76901e1022f87d71910f4e3e46f161299401f2074d0c"
func TestRecoveryMessage_DecodeFromTestnet(t *testing.T) {
hexDump := "00000000924b2fa6728782b6afb94873a377c49f31573005e7f2945beb27158ec2e887300d180000010000000000" +
"fd29024100000120003db64b5e8e4ab7138abe65a3be48d3a3f5d10013ab9ffee489706078714f1ea20161e7ba952fdfd5f543891b1fe053af401bc34e9e3f63c90e3c0d6675d156344b00008e4ab71300000000030000414079946c76007e4297b06b074a20dc1d1d6871c74976f244df81bd03f4158a11dd485ed50fc0cc7c6ad352addd8440c5a55d7b7449650bb200e5e58b1fb8a0390c010041403631a490b17ca4fcfe52ed2e7a4ca4c0d3fcca67e73a1ef071f385db1d37cefa7a2de6e56654788647e9142425c29449b0bbfee5c46a96c4bdc79b23c1f862fc02004140147914878c23a9624a62598cebe2c75fdce80c1e19b5c73aa511630f67d4e5a660c63daad7fcfa9bd944f258f51427cb80730b8beb3015a3c2766325bf291a8e02000000989f8fa676ed07885a46ee08af10e1fa1893ef20fbd557dc3c1a9dc498189d5fceff694dcb2085e4969d90c56433b88fd7ba1caef9363829c70419a5314ac36541404f3ee34e11c521f2e31fee439206474d36951443014354ce81b32bd1787e6a92212737f7f72bee59c403ff74292ebf78c4091081174b5921c148cedcbe7bd585000100acfc8399bda6429c64b5c09885a3e4f1a0629f59125df03be956c00f5bb77616c43e43250e96700f80c42ef3e169e9ff9f906518acf0da17c53563ba41d91ebc41409957436afd1736970d4b5e52b8d845663d6b0335a34cf78ece733c71be876cf30125e9bfea197a607ea6945cef7ef28a74676ec23d14378f7ec23964544b6710014140b634941ecab3a5dd7251f9213bfbcff2021b1e3d966e6800007ea6f0d72ec46d2c04c042800e103091d2f5d184d997a10b890b13bf06b1078a4f1822d722891a232102a7bc55fe8684e0119768d104ba30795bdcc86619e864add26156723ed185cd62ac"
data, err := hex.DecodeString(hexDump) data, err := hex.DecodeString(hexDump)
require.NoError(t, err) require.NoError(t, err)
buf := io.NewBinReaderFromBuf(data) buf := io.NewBinReaderFromBuf(data)
var p Payload p := NewPayload(netmode.TestNet)
p.DecodeBinary(buf) p.DecodeBinary(buf)
require.NoError(t, buf.Err) 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() buf.ReadB()
require.Equal(t, gio.EOF, buf.Err) require.Equal(t, gio.EOF, buf.Err)
} }
*/
func getKeys(t *testing.T, n int) []*privateKey { func getKeys(t *testing.T, n int) []*privateKey {
privs := make([]*privateKey, 0, n) privs := make([]*privateKey, 0, n)
for i := 0; i < n; i++ { for i := 0; i < n; i++ {

File diff suppressed because one or more lines are too long

View file

@ -7,6 +7,7 @@ import (
"io/ioutil" "io/ioutil"
"testing" "testing"
"github.com/nspcc-dev/neo-go/pkg/config/netmode"
"github.com/nspcc-dev/neo-go/pkg/internal/testserdes" "github.com/nspcc-dev/neo-go/pkg/internal/testserdes"
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
) )
@ -18,7 +19,7 @@ func getDecodedBlock(t *testing.T, i int) *Block {
b, err := hex.DecodeString(data["raw"].(string)) b, err := hex.DecodeString(data["raw"].(string))
require.NoError(t, err) require.NoError(t, err)
block := &Block{} block := New(netmode.TestNet)
require.NoError(t, testserdes.DecodeBinary(b, block)) require.NoError(t, testserdes.DecodeBinary(b, block))
return block return block

View file

@ -381,17 +381,27 @@ func TestHasBlock(t *testing.T) {
} }
} }
//TODO NEO3.0:Update binary
/*
func TestGetTransaction(t *testing.T) { func TestGetTransaction(t *testing.T) {
b1 := getDecodedBlock(t, 1)
block := getDecodedBlock(t, 2)
bc := newTestChain(t) 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 // 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. // and can't be verified, but we don't care about that in this test.
bc.config.VerifyBlocks = false bc.config.VerifyBlocks = false
bc.config.VerifyTransactions = false
assert.Nil(t, bc.AddBlock(b1)) assert.Nil(t, bc.AddBlock(b1))
block := bc.newBlock(tx2)
assert.Nil(t, bc.AddBlock(block)) assert.Nil(t, bc.AddBlock(block))
// Test unpersisted and persisted access // Test unpersisted and persisted access
@ -400,15 +410,13 @@ func TestGetTransaction(t *testing.T) {
require.Nil(t, err) require.Nil(t, err)
assert.Equal(t, block.Index, height) assert.Equal(t, block.Index, height)
assert.Equal(t, block.Transactions[0], tx) 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.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.Equal(t, 1, io.GetVarSize(tx.Scripts))
assert.NoError(t, bc.persist()) assert.NoError(t, bc.persist())
} }
} }
*/
func TestGetClaimable(t *testing.T) { func TestGetClaimable(t *testing.T) {
bc := newTestChain(t) bc := newTestChain(t)
defer bc.Close() defer bc.Close()

View file

@ -1,33 +1,49 @@
{ {
"raw": "00000000bf4421c88776c53b43ce1dc45463bfd2028e322fdfb60064be150ed3e36125d418f98ec3ed2c2d1c9427385e7b85d0d1a366e29c4e399693a59718380f8bbad6d6d90358010000004490d0bb7170726c59e75d652b5d3827bf04c165bbe9ef95cca4bf5501fd4501404edf5005771de04619235d5a4c7a9a11bb78e008541f1da7725f654c33380a3c87e2959a025da706d7255cb3a3fa07ebe9c6559d0d9e6213c68049168eb1056f4038a338f879930c8adc168983f60aae6f8542365d844f004976346b70fb0dd31aa1dbd4abd81e4a4aeef9941ecd4e2dd2c1a5b05e1cc74454d0403edaee6d7a4d4099d33c0b889bf6f3e6d87ab1b11140282e9a3265b0b9b918d6020b2c62d5a040c7e0c2c7c1dae3af9b19b178c71552ebd0b596e401c175067c70ea75717c8c00404e0ebd369e81093866fe29406dbf6b402c003774541799d08bf9bb0fc6070ec0f6bad908ab95f05fa64e682b485800b3c12102a8596e6c715ec76f4564d5eff34070e0521979fcd2cbbfa1456d97cc18d9b4a6ad87a97a2a0bcdedbf71b6c9676c645886056821b6f3fec8694894c66f41b762bc4e29e46ad15aee47f05d27d822f1552102486fd15702c4490a26703112a5cc1d0923fd697a33406bd5a1c00e0013b09a7021024c7b7fb6c310fccf1ba33b082519d82964ea93868d676662d4a59ad548df0e7d2102aaec38470f6aad0042c6e877cfd8087d2676b0f516fddd362801b9bd3936399e2103b209fd4f53a7170ea4444e0cb0a6bb6a53c2bd016926989cf85f9b0fba17a70c2103b8d9d5771d8f513aa0869b9cc8d50986403b78c6da36890638c3d46a5adce04a2102ca0e27697b9c248f6f16e085fd0061e26f44da85b58ee835c110caa5ec3ba5542102df48f60e8f3e01c48ff40b9b7f1310d7a8b2a193188befe1c2e3df740e89509357ae0100004490d0bb00000000", "raw": "000000002c343609ae0055bcdb57cc6e89b8e466cb264522feb1e0f916eb4a6a0d50f6a9129f211ef3bddbb1ed3ac496d6ee2de537764c4fb26c4b470e2f3a52fe6474dd75de3eb973010000c8000000e0a3c55cad72028fb5901748b19a27be21f6540401fd4a010c40d9bd422d752b9703080dd03c0b7182578d393e28f64ada3b76211f7b939c74a835bf354608af0ce8569ed9a65a7c578f1bbb742563c3086539e8b5ad5a0900590c405125cd7e76c2ce97546b9e5ea74ab313fb5875dc6d0567102ca2efee14e1de8d2b1deb332101b7c703d9c051ea6d43230db5fc787941bb40ad2c327a491936c10c402ad062631f244303d5818be9bce3d8aa5384ffaf8c531181166f45a230f96f93f42ea1c24286fe90e683249b39233223d84fe0996dcb458ef1288607ead535a50c40da40c40953d461d34014c5e66859874f6eec0740373054ea57dd66f615e2fa03fa395222b502f54210c0914975839c472702454e8d18040b702e6443f7e84f020c40393978243b8e81c6e08f0b021b9795c1c8f8d4d6155f0f16e28f30715bc38798a98b82d98e02a47f84d8b441ba157e8b280d27024fa1159e861c45fab9a647befdfd00150c2103009b7540e10f2562e5fd8fac9eaec25166a58b26e412348ff5a86927bfac22a20c21030205e9cefaea5a1dfc580af20c8d5aa2468bb0148f1a5e4605fc622c80e604ba0c210214baf0ceea3a66f17e7e1e839ea25fd8bed6cd82e6bb6e68250189065f44ff010c21023e9b32ea89b94d066e649b124fd50e396ee91369e8e2a6ae1b11c170d022256d0c2103408dcd416396f64783ac587ea1e1593c57d9fea880c8a6a1920e92a2594778060c2102a7834be9b32e2981d157cb5bbd3acb42cfd11ea5c3b10224d7a44e98c5910f1b0c2102ba2c70f5996f357a43198705859fae2cfea13e1172962800772b3d588a9d4abd170b41138defaf02045be5c3458d87a02c00f5f0617fc6ab5b000000000016f51200000000004615200001574d3c03df4a9b2772af08e4b296721009b7a6fd0100530c2102a7834be9b32e2981d157cb5bbd3acb42cfd11ea5c3b10224d7a44e98c5910f1b11c00c11726567697374657243616e6469646174650c1425059ecb4878d3a875f91c51ceded330d4575fde41627d5b5201420c40e3dfd02f6ec79dd6dbbe434540349187d975d5931bcf961c9d6b463d97165437049beec702ee14e69eb953c785134e689a3108464a130147174a80421756f391290c2102a7834be9b32e2981d157cb5bbd3acb42cfd11ea5c3b10224d7a44e98c5910f1b0b4195440d78",
"hash": "d782db8a38b0eea0d7394e0f007c61c71798867578c77c387c08113903946cc9", "hash": "0xfe767cae1a0a2c0825cc3610dd5fccd6b0dac4a5e2ab56644eea53cafce64848",
"size": 686, "size": 942,
"version": 0, "version": 0,
"previousblockhash": "d42561e3d30e15be6400b6df2f328e02d2bf6354c41dce433bc57687c82144bf", "previousblockhash": "0xa9f6500d6a4aeb16f9e0b1fe224526cb66e4b8896ecc57dbbc5500ae0936342c",
"merkleroot": "d6ba8b0f381897a59396394e9ce266a3d1d0857b5e3827941c2d2cedc38ef918", "merkleroot": "0xdd7464fe523a2f0e474b6cb24f4c7637e52deed696c43aedb1dbbdf31e219f12",
"time": 1476647382, "time": 1596540771957,
"index": 1, "index": 200,
"nonce": "6c727071bbd09044", "nextconsensus": "NgPkjjLTNcQad99iRYeXRUuowE4gxLAnDL",
"nextconsensus": "APyEx5f4Zm4oCHwFWiSTaph1fPBxZacYVR", "witnesses": [
"script": { {
"invocation": "404edf5005771de04619235d5a4c7a9a11bb78e008541f1da7725f654c33380a3c87e2959a025da706d7255cb3a3fa07ebe9c6559d0d9e6213c68049168eb1056f4038a338f879930c8adc168983f60aae6f8542365d844f004976346b70fb0dd31aa1dbd4abd81e4a4aeef9941ecd4e2dd2c1a5b05e1cc74454d0403edaee6d7a4d4099d33c0b889bf6f3e6d87ab1b11140282e9a3265b0b9b918d6020b2c62d5a040c7e0c2c7c1dae3af9b19b178c71552ebd0b596e401c175067c70ea75717c8c00404e0ebd369e81093866fe29406dbf6b402c003774541799d08bf9bb0fc6070ec0f6bad908ab95f05fa64e682b485800b3c12102a8596e6c715ec76f4564d5eff34070e0521979fcd2cbbfa1456d97cc18d9b4a6ad87a97a2a0bcdedbf71b6c9676c645886056821b6f3fec8694894c66f41b762bc4e29e46ad15aee47f05d27d822", "invocation": "DEDZvUItdSuXAwgN0DwLcYJXjTk+KPZK2jt2IR97k5x0qDW/NUYIrwzoVp7Zplp8V48bu3QlY8MIZTnota1aCQBZDEBRJc1+dsLOl1Rrnl6nSrMT+1h13G0FZxAsou/uFOHejSsd6zMhAbfHA9nAUeptQyMNtfx4eUG7QK0sMnpJGTbBDEAq0GJjHyRDA9WBi+m849iqU4T/r4xTEYEWb0WiMPlvk/QuocJChv6Q5oMkmzkjMiPYT+CZbctFjvEohgfq1TWlDEDaQMQJU9Rh00AUxeZoWYdPbuwHQDcwVOpX3Wb2FeL6A/o5UiK1AvVCEMCRSXWDnEcnAkVOjRgEC3AuZEP36E8CDEA5OXgkO46BxuCPCwIbl5XByPjU1hVfDxbijzBxW8OHmKmLgtmOAqR/hNi0QboVfosoDScCT6EVnoYcRfq5pke+",
"verification": "552102486fd15702c4490a26703112a5cc1d0923fd697a33406bd5a1c00e0013b09a7021024c7b7fb6c310fccf1ba33b082519d82964ea93868d676662d4a59ad548df0e7d2102aaec38470f6aad0042c6e877cfd8087d2676b0f516fddd362801b9bd3936399e2103b209fd4f53a7170ea4444e0cb0a6bb6a53c2bd016926989cf85f9b0fba17a70c2103b8d9d5771d8f513aa0869b9cc8d50986403b78c6da36890638c3d46a5adce04a2102ca0e27697b9c248f6f16e085fd0061e26f44da85b58ee835c110caa5ec3ba5542102df48f60e8f3e01c48ff40b9b7f1310d7a8b2a193188befe1c2e3df740e89509357ae" "verification": "FQwhAwCbdUDhDyVi5f2PrJ6uwlFmpYsm5BI0j/WoaSe/rCKiDCEDAgXpzvrqWh38WAryDI1aokaLsBSPGl5GBfxiLIDmBLoMIQIUuvDO6jpm8X5+HoOeol/YvtbNgua7bmglAYkGX0T/AQwhAj6bMuqJuU0GbmSbEk/VDjlu6RNp6OKmrhsRwXDQIiVtDCEDQI3NQWOW9keDrFh+oeFZPFfZ/qiAyKahkg6SollHeAYMIQKng0vpsy4pgdFXy1u9OstCz9EepcOxAiTXpE6YxZEPGwwhAroscPWZbzV6QxmHBYWfriz+oT4RcpYoAHcrPViKnUq9FwtBE43vrw=="
}
],
"consensusdata": {
"primary": 4,
"nonce": "2ca0878d45c3e55b"
}, },
"tx": [ "tx": [
{ {
"txid": "d6ba8b0f381897a59396394e9ce266a3d1d0857b5e3827941c2d2cedc38ef918", "hash": "0xca3e47909a27096ee880fac3b1f261dc912b0ba04c83f9142692cfefccedd41a",
"size": 10, "size": 242,
"type": "MinerTransaction",
"version": 0, "version": 0,
"attributes": [], "nonce": 2137125109,
"vin": [], "sender": "NTsaVneGBcARqEddHLAYaS6bncsZNS6X3S",
"vout": [], "sysfee": "6007750",
"sysfee": "0", "netfee": "1242390",
"netfee": "0", "validuntilblock": 2102598,
"witnesses": [], "signers": [
"nonce": 3151007812 {
"account": "0xfda6b709107296b2e408af72279b4adf033c4d57",
"scopes": "CalledByEntry"
} }
], ],
"confirmations": 2020977, "attributes": [],
"nextblockhash": "bf638e92c85016df9bc3b62b33f3879fa22d49d5f55d822b423149a3bca9e574" "script": "DCECp4NL6bMuKYHRV8tbvTrLQs/RHqXDsQIk16ROmMWRDxsRwAwRcmVnaXN0ZXJDYW5kaWRhdGUMFCUFnstIeNOodfkcUc7e0zDUV1/eQWJ9W1I=",
"witnesses": [
{
"invocation": "DEDj39Avbsed1tu+Q0VANJGH2XXVkxvPlhyda0Y9lxZUNwSb7scC7hTmnrlTx4UTTmiaMQhGShMBRxdKgEIXVvOR",
"verification": "DCECp4NL6bMuKYHRV8tbvTrLQs/RHqXDsQIk16ROmMWRDxsLQZVEDXg="
}
]
}
],
"confirmations": 67197,
"nextblockhash": "0x99b23a3bb26cae7e78b880a8b6bacf85a7ae923c7d6239f9a9f72604909fbba3"
} }

View file

@ -1,33 +1,24 @@
{ {
"raw": "00000000c96c94033911087c387cc77875869817c7617c000f4e39d7a0eeb0388adb82d74208df9542f56a42fb2764142d13274c951087c609565fd5c4ab9b57a183a1afead9035802000000b66fa838e89c9ab259e75d652b5d3827bf04c165bbe9ef95cca4bf5501fd450140e8a85159d8655c7b5a66429831eb15dabefc0f27a22bef67febb9eccb6859cc4c5c6ae675175a0bbefeeeeff2a8e9f175aaaae0796f3b5f29cb93b5b50fbf270409270a02cbbcb99969d6dc8a85708d5609dc1bba9569c849b53db7896c7f1ffd3adc789c0fe8400fb665478567448b4c4bd9c1657432591e4de83df10348f865a40724a9cf9d43eda558bfa8755e7bd1c0e9282f96164f4ff0b7369fd80e878cf49f2e61ed0fdf8cf218e7fdd471be5f29ef1242c39f3695d5decb169667fe0d3d140860da333249f7c54db09b548ad5d5e45fb8787238d51b35a6d4759f7990f47f00ff102e7b88f45acce423dd9f4b87dbf85e7e2c5c7a6aace11e62267c0bbe16b4028d272a701c22c5f8aa3495fa22d7d5a583518ef552e73813ee369c6d51ad2f246a24eb0092ebe7e1550d7de2ee09abad4dae4f4c0277317f5b1190041b9c2c2f1552102486fd15702c4490a26703112a5cc1d0923fd697a33406bd5a1c00e0013b09a7021024c7b7fb6c310fccf1ba33b082519d82964ea93868d676662d4a59ad548df0e7d2102aaec38470f6aad0042c6e877cfd8087d2676b0f516fddd362801b9bd3936399e2103b209fd4f53a7170ea4444e0cb0a6bb6a53c2bd016926989cf85f9b0fba17a70c2103b8d9d5771d8f513aa0869b9cc8d50986403b78c6da36890638c3d46a5adce04a2102ca0e27697b9c248f6f16e085fd0061e26f44da85b58ee835c110caa5ec3ba5542102df48f60e8f3e01c48ff40b9b7f1310d7a8b2a193188befe1c2e3df740e89509357ae010000b66fa83800000000", "raw": "00000000f791a09cffc085e7864d56ad8a74ee3e04f43c9affcbf14a87a903a889e8e215b5ef5b1df95f0fa5fe508157abdc64680a850dfb36018406758f02da97fc6ced5fccc5da73010000b88800005d12ac6c589d59f92e82d8bf60659cb716ffc1f101fd4a010c40fecf3fed562e1d39cfbc198b4bd5ccdfcea48b300917f3fb45c6f67004bfce8f816198018ccc93a595d62c1030eb29de56380ca67c087dadf4fd73e7f2ef2b910c409b6f623a720fabf6c21dc6e45f0a408a61b3664a81c08a644440b760884db2578fc00e0a16ac0c5bcb441713c0eb56b8448e6fe11c874cc78340ff62350e56f50c40b069d11b240c193fbbbb8115771827a133ca43e03d85ed0ce51893e1ea8ad9c779e8f683f1f455f57518c97a892fdfad7806364a11a9fb349b668a97862c503e0c4027fbc2eca5271da68905deee04ce3cd67450cf52c80c0ffea6d13c68708f3ba3ff6d4312bfff4d096ed5533342c5cf408c4130d05bfd0487dccb025a4b43c0fd0c408bbd56726fb88e4cf4f8dd33a57f9ab6297c8d84de210a585aaacb74cc00746daf44ea6e713d33c2e87344baec2f3cf70c72513d3bd5c7071c5c7d434c828c11fdfd00150c2103009b7540e10f2562e5fd8fac9eaec25166a58b26e412348ff5a86927bfac22a20c21030205e9cefaea5a1dfc580af20c8d5aa2468bb0148f1a5e4605fc622c80e604ba0c210214baf0ceea3a66f17e7e1e839ea25fd8bed6cd82e6bb6e68250189065f44ff010c2103408dcd416396f64783ac587ea1e1593c57d9fea880c8a6a1920e92a2594778060c2102a7834be9b32e2981d157cb5bbd3acb42cfd11ea5c3b10224d7a44e98c5910f1b0c2102ba2c70f5996f357a43198705859fae2cfea13e1172962800772b3d588a9d4abd0c2102f889ecd43c5126ff1932d75fa87dea34fc95325fb724db93c8f79fe32cc3f180170b41138defaf01001a82894d04b16977",
"hash": "0xbf638e92c85016df9bc3b62b33f3879fa22d49d5f55d822b423149a3bca9e574", "hash": "0xc39ffd0da100be6e8bd1ae536c8cb0b53f9988b635aca58ede3bdc3b6c832d78",
"size": 686, "size": 700,
"version": 0, "version": 0,
"previousblockhash": "0xd782db8a38b0eea0d7394e0f007c61c71798867578c77c387c08113903946cc9", "previousblockhash": "0x15e2e889a803a9874af1cbff9a3cf4043eee748aad564d86e785c0ff9ca091f7",
"merkleroot": "0xafa183a1579babc4d55f5609c68710954c27132d146427fb426af54295df0842", "merkleroot": "0xed6cfc97da028f7506840136fb0d850a6864dcab578150fea50f5ff91d5befb5",
"time": 1476647402, "time": 1597103262815,
"index": 2, "index": 35000,
"nonce": "b29a9ce838a86fb6", "nextconsensus": "NUQ6Q4BWvHU71HNxPQ4LMSHPMK1jSz1nw4",
"nextconsensus": "APyEx5f4Zm4oCHwFWiSTaph1fPBxZacYVR", "witnesses": [
"script": {
"invocation": "40e8a85159d8655c7b5a66429831eb15dabefc0f27a22bef67febb9eccb6859cc4c5c6ae675175a0bbefeeeeff2a8e9f175aaaae0796f3b5f29cb93b5b50fbf270409270a02cbbcb99969d6dc8a85708d5609dc1bba9569c849b53db7896c7f1ffd3adc789c0fe8400fb665478567448b4c4bd9c1657432591e4de83df10348f865a40724a9cf9d43eda558bfa8755e7bd1c0e9282f96164f4ff0b7369fd80e878cf49f2e61ed0fdf8cf218e7fdd471be5f29ef1242c39f3695d5decb169667fe0d3d140860da333249f7c54db09b548ad5d5e45fb8787238d51b35a6d4759f7990f47f00ff102e7b88f45acce423dd9f4b87dbf85e7e2c5c7a6aace11e62267c0bbe16b4028d272a701c22c5f8aa3495fa22d7d5a583518ef552e73813ee369c6d51ad2f246a24eb0092ebe7e1550d7de2ee09abad4dae4f4c0277317f5b1190041b9c2c2",
"verification": "552102486fd15702c4490a26703112a5cc1d0923fd697a33406bd5a1c00e0013b09a7021024c7b7fb6c310fccf1ba33b082519d82964ea93868d676662d4a59ad548df0e7d2102aaec38470f6aad0042c6e877cfd8087d2676b0f516fddd362801b9bd3936399e2103b209fd4f53a7170ea4444e0cb0a6bb6a53c2bd016926989cf85f9b0fba17a70c2103b8d9d5771d8f513aa0869b9cc8d50986403b78c6da36890638c3d46a5adce04a2102ca0e27697b9c248f6f16e085fd0061e26f44da85b58ee835c110caa5ec3ba5542102df48f60e8f3e01c48ff40b9b7f1310d7a8b2a193188befe1c2e3df740e89509357ae"
},
"tx": [
{ {
"txid": "0xafa183a1579babc4d55f5609c68710954c27132d146427fb426af54295df0842", "invocation": "DED+zz/tVi4dOc+8GYtL1czfzqSLMAkX8/tFxvZwBL/Oj4FhmAGMzJOlldYsEDDrKd5WOAymfAh9rfT9c+fy7yuRDECbb2I6cg+r9sIdxuRfCkCKYbNmSoHAimREQLdgiE2yV4/ADgoWrAxby0QXE8DrVrhEjm/hHIdMx4NA/2I1Dlb1DECwadEbJAwZP7u7gRV3GCehM8pD4D2F7QzlGJPh6orZx3no9oPx9FX1dRjJeokv3614BjZKEan7NJtmipeGLFA+DEAn+8LspScdpokF3u4EzjzWdFDPUsgMD/6m0TxocI87o/9tQxK//00JbtVTM0LFz0CMQTDQW/0Eh9zLAlpLQ8D9DECLvVZyb7iOTPT43TOlf5q2KXyNhN4hClhaqst0zAB0ba9E6m5xPTPC6HNEuuwvPPcMclE9O9XHBxxcfUNMgowR",
"size": 10, "verification": "FQwhAwCbdUDhDyVi5f2PrJ6uwlFmpYsm5BI0j/WoaSe/rCKiDCEDAgXpzvrqWh38WAryDI1aokaLsBSPGl5GBfxiLIDmBLoMIQIUuvDO6jpm8X5+HoOeol/YvtbNgua7bmglAYkGX0T/AQwhA0CNzUFjlvZHg6xYfqHhWTxX2f6ogMimoZIOkqJZR3gGDCECp4NL6bMuKYHRV8tbvTrLQs/RHqXDsQIk16ROmMWRDxsMIQK6LHD1mW81ekMZhwWFn64s/qE+EXKWKAB3Kz1Yip1KvQwhAviJ7NQ8USb/GTLXX6h96jT8lTJftyTbk8j3n+Msw/GAFwtBE43vrw=="
"type": "MinerTransaction",
"version": 0,
"attributes": [],
"vin": [],
"vout": [],
"sysfee": "0",
"netfee": "0",
"witnesses": [],
"nonce": 950562742
} }
], ],
"confirmations": 2021026, "consensusdata": {
"nextblockhash": "0x1fca8800f1ffbc9fb08bcfee1269461161d58dcee0252cf4db13220ba8189c5d" "primary": 0,
"nonce": "7769b1044d89821a"
},
"tx": [],
"confirmations": 32432,
"nextblockhash": "0x03bac24218cbee1326d1d3bfd7e18c96dd1cfa7f45d66ddf67f2523fc273b2aa"
} }

View file

@ -9,15 +9,14 @@ import (
) )
var ( var (
//TODO NEO3.0: Update binary // tx from testnet 58ea0709dac398c451fd51fdf4466f5257c77927c7909834a0ef3b469cd1a2ce
// https://neotracker.io/tx/fe4b3af60677204c57e573a57bdc97bc5059b05ad85b1474f84431f88d910f64 rawInvocationTX = "00be80024f7673890000000000261c130000000000e404210001f813c2cc8e18bbe4b3b87f8ef9105b50bb93918e01005d0300743ba40b0000000c14aa07cc3f2193a973904a09a6e60b87f1f96273970c14f813c2cc8e18bbe4b3b87f8ef9105b50bb93918e13c00c087472616e736665720c14bcaf41d684c7d4ad6ee0d99da9707b9d1f0c8e6641627d5b523801420c402360bbf64b9644c25f066dbd406454b07ab9f56e8e25d92d90c96c598f6c29d97eabdcf226f3575481662cfcdd064ee410978e5fae3f09a2f83129ba9cd82641290c2103caf763f91d3691cba5b5df3eb13e668fdace0295b37e2e259fd0fb152d354f900b4195440d78"
rawInvocationTX = "d101590400b33f7114839c33710da24cf8e7d536b8d244f3991cf565c8146063795d3b9b3cd55aef026eae992b91063db0db53c1087472616e7366657267c5cc1cb5392019e2cc4e6d6b5ea54c8d4b6d11acf166cb072961424c54f6000000000000000001206063795d3b9b3cd55aef026eae992b91063db0db0000014140c6a131c55ca38995402dff8e92ac55d89cbed4b98dfebbcb01acbc01bd78fa2ce2061be921b8999a9ab79c2958875bccfafe7ce1bbbaf1f56580815ea3a4feed232102d41ddce2c97be4c9aa571b8a32cbc305aa29afffbcae71b0ef568db0e93929aaac"
) )
func decodeTransaction(rawTX string, t *testing.T) *Transaction { func decodeTransaction(rawTX string, t *testing.T) *Transaction {
b, err1 := hex.DecodeString(rawTX) b, err1 := hex.DecodeString(rawTX)
assert.Nil(t, err1) assert.Nil(t, err1)
tx, err := NewTransactionFromBytes(netmode.UnitTestNet, b) tx, err := NewTransactionFromBytes(netmode.TestNet, b)
assert.NoError(t, err) assert.NoError(t, err)
return tx return tx
} }

View file

@ -1,10 +1,12 @@
package transaction package transaction
import ( import (
"encoding/base64"
"encoding/hex" "encoding/hex"
"testing" "testing"
"github.com/nspcc-dev/neo-go/pkg/config/netmode" "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/internal/testserdes"
"github.com/nspcc-dev/neo-go/pkg/util" "github.com/nspcc-dev/neo-go/pkg/util"
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
@ -34,33 +36,32 @@ func TestWitnessEncodeDecode(t *testing.T) {
t.Log(len(witDecode.InvocationScript)) t.Log(len(witDecode.InvocationScript))
} }
// TODO NEO3.0: update binary
/*
func TestDecodeEncodeInvocationTX(t *testing.T) { func TestDecodeEncodeInvocationTX(t *testing.T) {
tx := decodeTransaction(rawInvocationTX, t) tx := decodeTransaction(rawInvocationTX, t)
assert.Equal(t, tx.Type, InvocationType)
assert.IsType(t, tx.Data, &InvocationTX{})
invocTX := tx.Data.(*InvocationTX) script := "AwB0O6QLAAAADBSqB8w/IZOpc5BKCabmC4fx+WJzlwwU+BPCzI4Yu+SzuH+O+RBbULuTkY4TwAwIdHJhbnNmZXIMFLyvQdaEx9StbuDZnalwe50fDI5mQWJ9W1I4"
script := "0400b33f7114839c33710da24cf8e7d536b8d244f3991cf565c8146063795d3b9b3cd55aef026eae992b91063db0db53c1087472616e7366657267c5cc1cb5392019e2cc4e6d6b5ea54c8d4b6d11acf166cb072961424c54f6" assert.Equal(t, script, base64.StdEncoding.EncodeToString(tx.Script))
assert.Equal(t, script, hex.EncodeToString(invocTX.Script)) assert.Equal(t, uint32(1325564094), tx.Nonce)
assert.Equal(t, util.Fixed8(0), invocTX.Gas) 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, 1, len(tx.Signers))
assert.Equal(t, 0, len(tx.Inputs)) assert.Equal(t, CalledByEntry, tx.Signers[0].Scopes)
assert.Equal(t, 0, len(tx.Outputs)) assert.Equal(t, "NiXgSLtGUjTRTgp4y9ax7vyJ9UZAjsRDVt", address.Uint160ToString(tx.Signers[0].Account))
invoc := "40c6a131c55ca38995402dff8e92ac55d89cbed4b98dfebbcb01acbc01bd78fa2ce2061be921b8999a9ab79c2958875bccfafe7ce1bbbaf1f56580815ea3a4feed"
verif := "2102d41ddce2c97be4c9aa571b8a32cbc305aa29afffbcae71b0ef568db0e93929aaac" assert.Equal(t, 0, len(tx.Attributes))
invoc := "DEAjYLv2S5ZEwl8Gbb1AZFSwern1bo4l2S2QyWxZj2wp2X6r3PIm81dUgWYs/N0GTuQQl45frj8JovgxKbqc2CZB"
verif := "DCEDyvdj+R02kcultd8+sT5mj9rOApWzfi4ln9D7FS01T5ALQZVEDXg="
assert.Equal(t, 1, len(tx.Scripts)) assert.Equal(t, 1, len(tx.Scripts))
assert.Equal(t, invoc, hex.EncodeToString(tx.Scripts[0].InvocationScript)) assert.Equal(t, invoc, base64.StdEncoding.EncodeToString(tx.Scripts[0].InvocationScript))
assert.Equal(t, verif, hex.EncodeToString(tx.Scripts[0].VerificationScript)) assert.Equal(t, verif, base64.StdEncoding.EncodeToString(tx.Scripts[0].VerificationScript))
data, err := testserdes.EncodeBinary(tx) data, err := testserdes.EncodeBinary(tx)
assert.NoError(t, err) assert.NoError(t, err)
assert.Equal(t, rawInvocationTX, hex.EncodeToString(data)) assert.Equal(t, rawInvocationTX, hex.EncodeToString(data))
} }
*/
func TestNew(t *testing.T) { func TestNew(t *testing.T) {
script := []byte{0x51} script := []byte{0x51}