From 7d91a3a89e6455a29a815cc916e53076fdf05f91 Mon Sep 17 00:00:00 2001 From: Evgenii Stratonikov Date: Mon, 23 Nov 2020 14:09:00 +0300 Subject: [PATCH 1/4] pkg: move internal/ package to the root directory This way we can use it in scripts and cli. --- {pkg/internal => internal}/keytestcases/testcases.go | 0 {pkg/internal => internal}/random/random_util.go | 0 {pkg/internal => internal}/testchain/address.go | 0 {pkg/internal => internal}/testchain/network.go | 0 {pkg/internal => internal}/testserdes/testing.go | 0 pkg/compiler/debug_test.go | 2 +- pkg/consensus/cache_test.go | 2 +- pkg/consensus/commit_test.go | 2 +- pkg/consensus/consensus_test.go | 2 +- pkg/consensus/payload_test.go | 4 ++-- pkg/consensus/prepare_request_test.go | 4 ++-- pkg/consensus/recovery_message_test.go | 2 +- pkg/core/block/block_test.go | 2 +- pkg/core/block/header_test.go | 4 ++-- pkg/core/block/helper_test.go | 2 +- pkg/core/blockchain_test.go | 4 ++-- pkg/core/dao/cacheddao_test.go | 2 +- pkg/core/dao/dao_test.go | 2 +- pkg/core/helper_test.go | 4 ++-- pkg/core/interop_system_test.go | 2 +- pkg/core/mempool/mem_pool_test.go | 2 +- pkg/core/mpt/node_test.go | 4 ++-- pkg/core/mpt/trie_test.go | 2 +- pkg/core/native/oracle_types_test.go | 2 +- pkg/core/native_designate_test.go | 2 +- pkg/core/native_neo_test.go | 2 +- pkg/core/native_oracle_test.go | 2 +- pkg/core/native_policy_test.go | 2 +- pkg/core/state/contract_test.go | 2 +- pkg/core/state/mpt_root_test.go | 4 ++-- pkg/core/state/nep17_test.go | 4 ++-- pkg/core/state/notification_event_test.go | 4 ++-- pkg/core/state/oracle_test.go | 4 ++-- pkg/core/state/storage_item_test.go | 2 +- pkg/core/transaction/attribute_test.go | 4 ++-- pkg/core/transaction/oracle_test.go | 2 +- pkg/core/transaction/signer_test.go | 2 +- pkg/core/transaction/transaction_test.go | 4 ++-- pkg/core/transaction/witness_test.go | 2 +- pkg/crypto/keys/nep2_test.go | 2 +- pkg/crypto/keys/private_key_test.go | 2 +- pkg/crypto/keys/publickey_test.go | 2 +- pkg/network/message_test.go | 2 +- pkg/network/payload/address_test.go | 2 +- pkg/network/payload/getblockbyindex_test.go | 2 +- pkg/network/payload/getblocks_test.go | 2 +- pkg/network/payload/headers_test.go | 2 +- pkg/network/payload/inventory_test.go | 2 +- pkg/network/payload/merkleblock_test.go | 2 +- pkg/network/payload/ping_test.go | 2 +- pkg/network/payload/version_test.go | 2 +- pkg/rpc/client/rpc_test.go | 2 +- pkg/rpc/response/result/mpt_test.go | 4 ++-- pkg/rpc/server/client_test.go | 2 +- pkg/rpc/server/server_test.go | 4 ++-- pkg/rpc/server/subscription_test.go | 2 +- pkg/smartcontract/context/context_test.go | 2 +- pkg/smartcontract/context/item_test.go | 4 ++-- pkg/smartcontract/manifest/container_test.go | 4 ++-- pkg/smartcontract/manifest/permission_test.go | 2 +- pkg/smartcontract/nef/nef_test.go | 2 +- pkg/smartcontract/parameter_test.go | 2 +- pkg/util/fixed8_test.go | 2 +- pkg/util/uint160_test.go | 2 +- pkg/util/uint256_test.go | 2 +- pkg/vm/vm_test.go | 2 +- pkg/wallet/account_test.go | 2 +- 67 files changed, 78 insertions(+), 78 deletions(-) rename {pkg/internal => internal}/keytestcases/testcases.go (100%) rename {pkg/internal => internal}/random/random_util.go (100%) rename {pkg/internal => internal}/testchain/address.go (100%) rename {pkg/internal => internal}/testchain/network.go (100%) rename {pkg/internal => internal}/testserdes/testing.go (100%) diff --git a/pkg/internal/keytestcases/testcases.go b/internal/keytestcases/testcases.go similarity index 100% rename from pkg/internal/keytestcases/testcases.go rename to internal/keytestcases/testcases.go diff --git a/pkg/internal/random/random_util.go b/internal/random/random_util.go similarity index 100% rename from pkg/internal/random/random_util.go rename to internal/random/random_util.go diff --git a/pkg/internal/testchain/address.go b/internal/testchain/address.go similarity index 100% rename from pkg/internal/testchain/address.go rename to internal/testchain/address.go diff --git a/pkg/internal/testchain/network.go b/internal/testchain/network.go similarity index 100% rename from pkg/internal/testchain/network.go rename to internal/testchain/network.go diff --git a/pkg/internal/testserdes/testing.go b/internal/testserdes/testing.go similarity index 100% rename from pkg/internal/testserdes/testing.go rename to internal/testserdes/testing.go diff --git a/pkg/compiler/debug_test.go b/pkg/compiler/debug_test.go index 6db467af8..2993f3854 100644 --- a/pkg/compiler/debug_test.go +++ b/pkg/compiler/debug_test.go @@ -3,8 +3,8 @@ package compiler import ( "testing" + "github.com/nspcc-dev/neo-go/internal/testserdes" "github.com/nspcc-dev/neo-go/pkg/crypto/hash" - "github.com/nspcc-dev/neo-go/pkg/internal/testserdes" "github.com/nspcc-dev/neo-go/pkg/smartcontract" "github.com/nspcc-dev/neo-go/pkg/smartcontract/manifest" "github.com/nspcc-dev/neo-go/pkg/util" diff --git a/pkg/consensus/cache_test.go b/pkg/consensus/cache_test.go index cd4ebe5a3..a1069686f 100644 --- a/pkg/consensus/cache_test.go +++ b/pkg/consensus/cache_test.go @@ -4,7 +4,7 @@ import ( "testing" "github.com/nspcc-dev/dbft/payload" - "github.com/nspcc-dev/neo-go/pkg/internal/random" + "github.com/nspcc-dev/neo-go/internal/random" "github.com/stretchr/testify/require" ) diff --git a/pkg/consensus/commit_test.go b/pkg/consensus/commit_test.go index b68e2b6d3..8616894ec 100644 --- a/pkg/consensus/commit_test.go +++ b/pkg/consensus/commit_test.go @@ -3,7 +3,7 @@ package consensus import ( "testing" - "github.com/nspcc-dev/neo-go/pkg/internal/random" + "github.com/nspcc-dev/neo-go/internal/random" "github.com/stretchr/testify/require" ) diff --git a/pkg/consensus/consensus_test.go b/pkg/consensus/consensus_test.go index 3fa50fb62..9dce6b281 100644 --- a/pkg/consensus/consensus_test.go +++ b/pkg/consensus/consensus_test.go @@ -7,6 +7,7 @@ import ( "github.com/nspcc-dev/dbft/block" "github.com/nspcc-dev/dbft/payload" "github.com/nspcc-dev/dbft/timer" + "github.com/nspcc-dev/neo-go/internal/testchain" "github.com/nspcc-dev/neo-go/pkg/config" "github.com/nspcc-dev/neo-go/pkg/config/netmode" "github.com/nspcc-dev/neo-go/pkg/core" @@ -16,7 +17,6 @@ import ( "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/crypto/keys" - "github.com/nspcc-dev/neo-go/pkg/internal/testchain" "github.com/nspcc-dev/neo-go/pkg/io" "github.com/nspcc-dev/neo-go/pkg/smartcontract" "github.com/nspcc-dev/neo-go/pkg/util" diff --git a/pkg/consensus/payload_test.go b/pkg/consensus/payload_test.go index 9ebbc5201..f63349440 100644 --- a/pkg/consensus/payload_test.go +++ b/pkg/consensus/payload_test.go @@ -5,11 +5,11 @@ import ( "testing" "github.com/nspcc-dev/dbft/payload" + "github.com/nspcc-dev/neo-go/internal/random" + "github.com/nspcc-dev/neo-go/internal/testserdes" "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/keys" - "github.com/nspcc-dev/neo-go/pkg/internal/random" - "github.com/nspcc-dev/neo-go/pkg/internal/testserdes" "github.com/nspcc-dev/neo-go/pkg/io" "github.com/nspcc-dev/neo-go/pkg/util" "github.com/nspcc-dev/neo-go/pkg/vm/opcode" diff --git a/pkg/consensus/prepare_request_test.go b/pkg/consensus/prepare_request_test.go index ef51a7d56..f40763c02 100644 --- a/pkg/consensus/prepare_request_test.go +++ b/pkg/consensus/prepare_request_test.go @@ -3,9 +3,9 @@ package consensus import ( "testing" + "github.com/nspcc-dev/neo-go/internal/random" + "github.com/nspcc-dev/neo-go/internal/testserdes" "github.com/nspcc-dev/neo-go/pkg/core/block" - "github.com/nspcc-dev/neo-go/pkg/internal/random" - "github.com/nspcc-dev/neo-go/pkg/internal/testserdes" "github.com/nspcc-dev/neo-go/pkg/util" "github.com/stretchr/testify/require" ) diff --git a/pkg/consensus/recovery_message_test.go b/pkg/consensus/recovery_message_test.go index b0fb4237b..0759ae7fa 100644 --- a/pkg/consensus/recovery_message_test.go +++ b/pkg/consensus/recovery_message_test.go @@ -5,9 +5,9 @@ import ( "github.com/nspcc-dev/dbft/crypto" "github.com/nspcc-dev/dbft/payload" + "github.com/nspcc-dev/neo-go/internal/testchain" "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/internal/testchain" "github.com/nspcc-dev/neo-go/pkg/util" "github.com/stretchr/testify/require" ) diff --git a/pkg/core/block/block_test.go b/pkg/core/block/block_test.go index a681056da..144c1995f 100644 --- a/pkg/core/block/block_test.go +++ b/pkg/core/block/block_test.go @@ -7,11 +7,11 @@ import ( "strings" "testing" + "github.com/nspcc-dev/neo-go/internal/testserdes" "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" diff --git a/pkg/core/block/header_test.go b/pkg/core/block/header_test.go index 4fc865757..7ad770cbf 100644 --- a/pkg/core/block/header_test.go +++ b/pkg/core/block/header_test.go @@ -4,10 +4,10 @@ import ( "testing" "time" + "github.com/nspcc-dev/neo-go/internal/random" + "github.com/nspcc-dev/neo-go/internal/testserdes" "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/internal/random" - "github.com/nspcc-dev/neo-go/pkg/internal/testserdes" "github.com/nspcc-dev/neo-go/pkg/util" "github.com/stretchr/testify/assert" ) diff --git a/pkg/core/block/helper_test.go b/pkg/core/block/helper_test.go index cefea3959..c52a39a94 100644 --- a/pkg/core/block/helper_test.go +++ b/pkg/core/block/helper_test.go @@ -7,8 +7,8 @@ import ( "io/ioutil" "testing" + "github.com/nspcc-dev/neo-go/internal/testserdes" "github.com/nspcc-dev/neo-go/pkg/config/netmode" - "github.com/nspcc-dev/neo-go/pkg/internal/testserdes" "github.com/stretchr/testify/require" ) diff --git a/pkg/core/blockchain_test.go b/pkg/core/blockchain_test.go index db983f3fb..cd7f37d8b 100644 --- a/pkg/core/blockchain_test.go +++ b/pkg/core/blockchain_test.go @@ -7,6 +7,8 @@ import ( "testing" "time" + "github.com/nspcc-dev/neo-go/internal/random" + "github.com/nspcc-dev/neo-go/internal/testchain" "github.com/nspcc-dev/neo-go/pkg/config/netmode" "github.com/nspcc-dev/neo-go/pkg/core/block" "github.com/nspcc-dev/neo-go/pkg/core/fee" @@ -18,8 +20,6 @@ import ( "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/crypto/keys" - "github.com/nspcc-dev/neo-go/pkg/internal/random" - "github.com/nspcc-dev/neo-go/pkg/internal/testchain" "github.com/nspcc-dev/neo-go/pkg/io" "github.com/nspcc-dev/neo-go/pkg/smartcontract" "github.com/nspcc-dev/neo-go/pkg/smartcontract/trigger" diff --git a/pkg/core/dao/cacheddao_test.go b/pkg/core/dao/cacheddao_test.go index 8263aa707..190590f15 100644 --- a/pkg/core/dao/cacheddao_test.go +++ b/pkg/core/dao/cacheddao_test.go @@ -3,11 +3,11 @@ package dao import ( "testing" + "github.com/nspcc-dev/neo-go/internal/random" "github.com/nspcc-dev/neo-go/pkg/config/netmode" "github.com/nspcc-dev/neo-go/pkg/core/state" "github.com/nspcc-dev/neo-go/pkg/core/storage" "github.com/nspcc-dev/neo-go/pkg/crypto/hash" - "github.com/nspcc-dev/neo-go/pkg/internal/random" "github.com/nspcc-dev/neo-go/pkg/smartcontract/manifest" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" diff --git a/pkg/core/dao/dao_test.go b/pkg/core/dao/dao_test.go index 74f76a1a7..9a583084e 100644 --- a/pkg/core/dao/dao_test.go +++ b/pkg/core/dao/dao_test.go @@ -4,12 +4,12 @@ import ( "encoding/binary" "testing" + "github.com/nspcc-dev/neo-go/internal/random" "github.com/nspcc-dev/neo-go/pkg/config/netmode" "github.com/nspcc-dev/neo-go/pkg/core/block" "github.com/nspcc-dev/neo-go/pkg/core/state" "github.com/nspcc-dev/neo-go/pkg/core/storage" "github.com/nspcc-dev/neo-go/pkg/core/transaction" - "github.com/nspcc-dev/neo-go/pkg/internal/random" "github.com/nspcc-dev/neo-go/pkg/io" "github.com/nspcc-dev/neo-go/pkg/smartcontract/trigger" "github.com/nspcc-dev/neo-go/pkg/vm/opcode" diff --git a/pkg/core/helper_test.go b/pkg/core/helper_test.go index aed64ffe1..0af065e3d 100644 --- a/pkg/core/helper_test.go +++ b/pkg/core/helper_test.go @@ -11,6 +11,8 @@ import ( "testing" "time" + "github.com/nspcc-dev/neo-go/internal/testchain" + "github.com/nspcc-dev/neo-go/internal/testserdes" "github.com/nspcc-dev/neo-go/pkg/compiler" "github.com/nspcc-dev/neo-go/pkg/config" "github.com/nspcc-dev/neo-go/pkg/core/block" @@ -20,8 +22,6 @@ import ( "github.com/nspcc-dev/neo-go/pkg/core/storage" "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/internal/testchain" - "github.com/nspcc-dev/neo-go/pkg/internal/testserdes" "github.com/nspcc-dev/neo-go/pkg/io" "github.com/nspcc-dev/neo-go/pkg/smartcontract" "github.com/nspcc-dev/neo-go/pkg/util" diff --git a/pkg/core/interop_system_test.go b/pkg/core/interop_system_test.go index f714b855f..5f0be0574 100644 --- a/pkg/core/interop_system_test.go +++ b/pkg/core/interop_system_test.go @@ -7,6 +7,7 @@ import ( "testing" "github.com/nspcc-dev/dbft/crypto" + "github.com/nspcc-dev/neo-go/internal/random" "github.com/nspcc-dev/neo-go/pkg/config/netmode" "github.com/nspcc-dev/neo-go/pkg/core/interop" "github.com/nspcc-dev/neo-go/pkg/core/interop/callback" @@ -17,7 +18,6 @@ import ( "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/crypto/keys" - "github.com/nspcc-dev/neo-go/pkg/internal/random" "github.com/nspcc-dev/neo-go/pkg/io" "github.com/nspcc-dev/neo-go/pkg/smartcontract" "github.com/nspcc-dev/neo-go/pkg/smartcontract/manifest" diff --git a/pkg/core/mempool/mem_pool_test.go b/pkg/core/mempool/mem_pool_test.go index eed3bf638..31fcf7212 100644 --- a/pkg/core/mempool/mem_pool_test.go +++ b/pkg/core/mempool/mem_pool_test.go @@ -7,9 +7,9 @@ import ( "testing" "time" + "github.com/nspcc-dev/neo-go/internal/random" "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/internal/random" "github.com/nspcc-dev/neo-go/pkg/util" "github.com/nspcc-dev/neo-go/pkg/vm/opcode" "github.com/stretchr/testify/assert" diff --git a/pkg/core/mpt/node_test.go b/pkg/core/mpt/node_test.go index dc2b66ec6..393585493 100644 --- a/pkg/core/mpt/node_test.go +++ b/pkg/core/mpt/node_test.go @@ -4,8 +4,8 @@ import ( "encoding/json" "testing" - "github.com/nspcc-dev/neo-go/pkg/internal/random" - "github.com/nspcc-dev/neo-go/pkg/internal/testserdes" + "github.com/nspcc-dev/neo-go/internal/random" + "github.com/nspcc-dev/neo-go/internal/testserdes" "github.com/nspcc-dev/neo-go/pkg/io" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" diff --git a/pkg/core/mpt/trie_test.go b/pkg/core/mpt/trie_test.go index e8fc532e5..f1fb1aa5a 100644 --- a/pkg/core/mpt/trie_test.go +++ b/pkg/core/mpt/trie_test.go @@ -3,8 +3,8 @@ package mpt import ( "testing" + "github.com/nspcc-dev/neo-go/internal/random" "github.com/nspcc-dev/neo-go/pkg/core/storage" - "github.com/nspcc-dev/neo-go/pkg/internal/random" "github.com/stretchr/testify/require" ) diff --git a/pkg/core/native/oracle_types_test.go b/pkg/core/native/oracle_types_test.go index 7882fbb73..78acf7bf2 100644 --- a/pkg/core/native/oracle_types_test.go +++ b/pkg/core/native/oracle_types_test.go @@ -3,8 +3,8 @@ package native import ( "testing" + "github.com/nspcc-dev/neo-go/internal/testserdes" "github.com/nspcc-dev/neo-go/pkg/crypto/keys" - "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/stackitem" "github.com/stretchr/testify/require" diff --git a/pkg/core/native_designate_test.go b/pkg/core/native_designate_test.go index dcc75c17e..f29ccdb7c 100644 --- a/pkg/core/native_designate_test.go +++ b/pkg/core/native_designate_test.go @@ -4,12 +4,12 @@ import ( "errors" "testing" + "github.com/nspcc-dev/neo-go/internal/testchain" "github.com/nspcc-dev/neo-go/pkg/config/netmode" "github.com/nspcc-dev/neo-go/pkg/core/block" "github.com/nspcc-dev/neo-go/pkg/core/native" "github.com/nspcc-dev/neo-go/pkg/core/transaction" "github.com/nspcc-dev/neo-go/pkg/crypto/keys" - "github.com/nspcc-dev/neo-go/pkg/internal/testchain" "github.com/nspcc-dev/neo-go/pkg/io" "github.com/nspcc-dev/neo-go/pkg/smartcontract/trigger" "github.com/nspcc-dev/neo-go/pkg/vm" diff --git a/pkg/core/native_neo_test.go b/pkg/core/native_neo_test.go index 413d1759c..fa25354e3 100644 --- a/pkg/core/native_neo_test.go +++ b/pkg/core/native_neo_test.go @@ -5,11 +5,11 @@ import ( "sort" "testing" + "github.com/nspcc-dev/neo-go/internal/testchain" "github.com/nspcc-dev/neo-go/pkg/config/netmode" "github.com/nspcc-dev/neo-go/pkg/core/native" "github.com/nspcc-dev/neo-go/pkg/core/transaction" "github.com/nspcc-dev/neo-go/pkg/crypto/keys" - "github.com/nspcc-dev/neo-go/pkg/internal/testchain" "github.com/nspcc-dev/neo-go/pkg/io" "github.com/nspcc-dev/neo-go/pkg/smartcontract/trigger" "github.com/nspcc-dev/neo-go/pkg/util" diff --git a/pkg/core/native_oracle_test.go b/pkg/core/native_oracle_test.go index 8e091a28b..9e4bd34ce 100644 --- a/pkg/core/native_oracle_test.go +++ b/pkg/core/native_oracle_test.go @@ -5,6 +5,7 @@ import ( "math/big" "testing" + "github.com/nspcc-dev/neo-go/internal/testchain" "github.com/nspcc-dev/neo-go/pkg/config/netmode" "github.com/nspcc-dev/neo-go/pkg/core/block" "github.com/nspcc-dev/neo-go/pkg/core/interop/interopnames" @@ -12,7 +13,6 @@ import ( "github.com/nspcc-dev/neo-go/pkg/core/state" "github.com/nspcc-dev/neo-go/pkg/core/transaction" "github.com/nspcc-dev/neo-go/pkg/crypto/keys" - "github.com/nspcc-dev/neo-go/pkg/internal/testchain" "github.com/nspcc-dev/neo-go/pkg/io" "github.com/nspcc-dev/neo-go/pkg/smartcontract" "github.com/nspcc-dev/neo-go/pkg/smartcontract/manifest" diff --git a/pkg/core/native_policy_test.go b/pkg/core/native_policy_test.go index 8a5a617fa..f9a04eb66 100644 --- a/pkg/core/native_policy_test.go +++ b/pkg/core/native_policy_test.go @@ -4,12 +4,12 @@ import ( "math/big" "testing" + "github.com/nspcc-dev/neo-go/internal/random" "github.com/nspcc-dev/neo-go/pkg/core/block" "github.com/nspcc-dev/neo-go/pkg/core/native" "github.com/nspcc-dev/neo-go/pkg/core/state" "github.com/nspcc-dev/neo-go/pkg/core/transaction" "github.com/nspcc-dev/neo-go/pkg/encoding/bigint" - "github.com/nspcc-dev/neo-go/pkg/internal/random" "github.com/nspcc-dev/neo-go/pkg/io" "github.com/nspcc-dev/neo-go/pkg/network/payload" "github.com/nspcc-dev/neo-go/pkg/smartcontract/trigger" diff --git a/pkg/core/state/contract_test.go b/pkg/core/state/contract_test.go index 95b8ccb52..90da814ea 100644 --- a/pkg/core/state/contract_test.go +++ b/pkg/core/state/contract_test.go @@ -3,8 +3,8 @@ package state import ( "testing" + "github.com/nspcc-dev/neo-go/internal/testserdes" "github.com/nspcc-dev/neo-go/pkg/crypto/hash" - "github.com/nspcc-dev/neo-go/pkg/internal/testserdes" "github.com/nspcc-dev/neo-go/pkg/smartcontract" "github.com/nspcc-dev/neo-go/pkg/smartcontract/manifest" "github.com/stretchr/testify/assert" diff --git a/pkg/core/state/mpt_root_test.go b/pkg/core/state/mpt_root_test.go index f1c0b5c61..da9ff9c46 100644 --- a/pkg/core/state/mpt_root_test.go +++ b/pkg/core/state/mpt_root_test.go @@ -5,9 +5,9 @@ import ( "math/rand" "testing" + "github.com/nspcc-dev/neo-go/internal/random" + "github.com/nspcc-dev/neo-go/internal/testserdes" "github.com/nspcc-dev/neo-go/pkg/core/transaction" - "github.com/nspcc-dev/neo-go/pkg/internal/random" - "github.com/nspcc-dev/neo-go/pkg/internal/testserdes" "github.com/nspcc-dev/neo-go/pkg/util" "github.com/stretchr/testify/require" ) diff --git a/pkg/core/state/nep17_test.go b/pkg/core/state/nep17_test.go index e423e408a..5a8f2db46 100644 --- a/pkg/core/state/nep17_test.go +++ b/pkg/core/state/nep17_test.go @@ -6,8 +6,8 @@ import ( "testing" "time" - "github.com/nspcc-dev/neo-go/pkg/internal/random" - "github.com/nspcc-dev/neo-go/pkg/internal/testserdes" + "github.com/nspcc-dev/neo-go/internal/random" + "github.com/nspcc-dev/neo-go/internal/testserdes" "github.com/nspcc-dev/neo-go/pkg/util" "github.com/stretchr/testify/require" ) diff --git a/pkg/core/state/notification_event_test.go b/pkg/core/state/notification_event_test.go index 525397af0..631fbeffe 100644 --- a/pkg/core/state/notification_event_test.go +++ b/pkg/core/state/notification_event_test.go @@ -4,8 +4,8 @@ import ( "encoding/json" "testing" - "github.com/nspcc-dev/neo-go/pkg/internal/random" - "github.com/nspcc-dev/neo-go/pkg/internal/testserdes" + "github.com/nspcc-dev/neo-go/internal/random" + "github.com/nspcc-dev/neo-go/internal/testserdes" "github.com/nspcc-dev/neo-go/pkg/smartcontract/trigger" "github.com/nspcc-dev/neo-go/pkg/vm" "github.com/nspcc-dev/neo-go/pkg/vm/stackitem" diff --git a/pkg/core/state/oracle_test.go b/pkg/core/state/oracle_test.go index d57f98b73..3c3a3abe2 100644 --- a/pkg/core/state/oracle_test.go +++ b/pkg/core/state/oracle_test.go @@ -4,8 +4,8 @@ import ( "math/big" "testing" - "github.com/nspcc-dev/neo-go/pkg/internal/random" - "github.com/nspcc-dev/neo-go/pkg/internal/testserdes" + "github.com/nspcc-dev/neo-go/internal/random" + "github.com/nspcc-dev/neo-go/internal/testserdes" "github.com/nspcc-dev/neo-go/pkg/io" "github.com/nspcc-dev/neo-go/pkg/vm/stackitem" "github.com/stretchr/testify/require" diff --git a/pkg/core/state/storage_item_test.go b/pkg/core/state/storage_item_test.go index 1df6165df..0da9c2a31 100644 --- a/pkg/core/state/storage_item_test.go +++ b/pkg/core/state/storage_item_test.go @@ -3,7 +3,7 @@ package state import ( "testing" - "github.com/nspcc-dev/neo-go/pkg/internal/testserdes" + "github.com/nspcc-dev/neo-go/internal/testserdes" ) func TestEncodeDecodeStorageItem(t *testing.T) { diff --git a/pkg/core/transaction/attribute_test.go b/pkg/core/transaction/attribute_test.go index b769fe88b..935746422 100644 --- a/pkg/core/transaction/attribute_test.go +++ b/pkg/core/transaction/attribute_test.go @@ -5,8 +5,8 @@ import ( "encoding/json" "testing" - "github.com/nspcc-dev/neo-go/pkg/internal/random" - "github.com/nspcc-dev/neo-go/pkg/internal/testserdes" + "github.com/nspcc-dev/neo-go/internal/random" + "github.com/nspcc-dev/neo-go/internal/testserdes" "github.com/stretchr/testify/require" ) diff --git a/pkg/core/transaction/oracle_test.go b/pkg/core/transaction/oracle_test.go index 715f717bc..f0ec24a09 100644 --- a/pkg/core/transaction/oracle_test.go +++ b/pkg/core/transaction/oracle_test.go @@ -6,7 +6,7 @@ import ( "math/rand" "testing" - "github.com/nspcc-dev/neo-go/pkg/internal/testserdes" + "github.com/nspcc-dev/neo-go/internal/testserdes" "github.com/stretchr/testify/require" ) diff --git a/pkg/core/transaction/signer_test.go b/pkg/core/transaction/signer_test.go index efe5413b0..85ae3823a 100644 --- a/pkg/core/transaction/signer_test.go +++ b/pkg/core/transaction/signer_test.go @@ -3,7 +3,7 @@ package transaction import ( "testing" - "github.com/nspcc-dev/neo-go/pkg/internal/testserdes" + "github.com/nspcc-dev/neo-go/internal/testserdes" "github.com/nspcc-dev/neo-go/pkg/util" ) diff --git a/pkg/core/transaction/transaction_test.go b/pkg/core/transaction/transaction_test.go index 510351639..84c08ee80 100644 --- a/pkg/core/transaction/transaction_test.go +++ b/pkg/core/transaction/transaction_test.go @@ -10,10 +10,10 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" + "github.com/nspcc-dev/neo-go/internal/random" + "github.com/nspcc-dev/neo-go/internal/testserdes" "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/random" - "github.com/nspcc-dev/neo-go/pkg/internal/testserdes" "github.com/nspcc-dev/neo-go/pkg/util" ) diff --git a/pkg/core/transaction/witness_test.go b/pkg/core/transaction/witness_test.go index ac135e11d..a8b945c12 100644 --- a/pkg/core/transaction/witness_test.go +++ b/pkg/core/transaction/witness_test.go @@ -3,7 +3,7 @@ package transaction import ( "testing" - "github.com/nspcc-dev/neo-go/pkg/internal/testserdes" + "github.com/nspcc-dev/neo-go/internal/testserdes" "github.com/stretchr/testify/require" ) diff --git a/pkg/crypto/keys/nep2_test.go b/pkg/crypto/keys/nep2_test.go index 98e48010d..218ab050a 100644 --- a/pkg/crypto/keys/nep2_test.go +++ b/pkg/crypto/keys/nep2_test.go @@ -3,7 +3,7 @@ package keys import ( "testing" - "github.com/nspcc-dev/neo-go/pkg/internal/keytestcases" + "github.com/nspcc-dev/neo-go/internal/keytestcases" "github.com/stretchr/testify/assert" ) diff --git a/pkg/crypto/keys/private_key_test.go b/pkg/crypto/keys/private_key_test.go index d8d7c1dc2..9089aa302 100644 --- a/pkg/crypto/keys/private_key_test.go +++ b/pkg/crypto/keys/private_key_test.go @@ -5,7 +5,7 @@ import ( "strings" "testing" - "github.com/nspcc-dev/neo-go/pkg/internal/keytestcases" + "github.com/nspcc-dev/neo-go/internal/keytestcases" "github.com/stretchr/testify/assert" ) diff --git a/pkg/crypto/keys/publickey_test.go b/pkg/crypto/keys/publickey_test.go index 105a83712..06c704232 100644 --- a/pkg/crypto/keys/publickey_test.go +++ b/pkg/crypto/keys/publickey_test.go @@ -8,7 +8,7 @@ import ( "sort" "testing" - "github.com/nspcc-dev/neo-go/pkg/internal/testserdes" + "github.com/nspcc-dev/neo-go/internal/testserdes" "github.com/stretchr/testify/require" ) diff --git a/pkg/network/message_test.go b/pkg/network/message_test.go index fae10ad14..dd59aac16 100644 --- a/pkg/network/message_test.go +++ b/pkg/network/message_test.go @@ -4,9 +4,9 @@ import ( "testing" "time" + "github.com/nspcc-dev/neo-go/internal/testserdes" "github.com/nspcc-dev/neo-go/pkg/core/block" "github.com/nspcc-dev/neo-go/pkg/core/transaction" - "github.com/nspcc-dev/neo-go/pkg/internal/testserdes" "github.com/nspcc-dev/neo-go/pkg/network/capability" "github.com/nspcc-dev/neo-go/pkg/network/payload" "github.com/nspcc-dev/neo-go/pkg/util" diff --git a/pkg/network/payload/address_test.go b/pkg/network/payload/address_test.go index b429a8a24..9baad63ea 100644 --- a/pkg/network/payload/address_test.go +++ b/pkg/network/payload/address_test.go @@ -6,7 +6,7 @@ import ( "testing" "time" - "github.com/nspcc-dev/neo-go/pkg/internal/testserdes" + "github.com/nspcc-dev/neo-go/internal/testserdes" "github.com/nspcc-dev/neo-go/pkg/network/capability" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" diff --git a/pkg/network/payload/getblockbyindex_test.go b/pkg/network/payload/getblockbyindex_test.go index 1bd2f3452..962087b84 100644 --- a/pkg/network/payload/getblockbyindex_test.go +++ b/pkg/network/payload/getblockbyindex_test.go @@ -3,7 +3,7 @@ package payload import ( "testing" - "github.com/nspcc-dev/neo-go/pkg/internal/testserdes" + "github.com/nspcc-dev/neo-go/internal/testserdes" "github.com/stretchr/testify/require" ) diff --git a/pkg/network/payload/getblocks_test.go b/pkg/network/payload/getblocks_test.go index 8d720b12b..52c41e4a1 100644 --- a/pkg/network/payload/getblocks_test.go +++ b/pkg/network/payload/getblocks_test.go @@ -3,8 +3,8 @@ package payload import ( "testing" + "github.com/nspcc-dev/neo-go/internal/testserdes" "github.com/nspcc-dev/neo-go/pkg/crypto/hash" - "github.com/nspcc-dev/neo-go/pkg/internal/testserdes" "github.com/stretchr/testify/require" ) diff --git a/pkg/network/payload/headers_test.go b/pkg/network/payload/headers_test.go index 94ebdaf8b..38ef5183b 100644 --- a/pkg/network/payload/headers_test.go +++ b/pkg/network/payload/headers_test.go @@ -3,9 +3,9 @@ package payload import ( "testing" + "github.com/nspcc-dev/neo-go/internal/testserdes" "github.com/nspcc-dev/neo-go/pkg/core/block" "github.com/nspcc-dev/neo-go/pkg/core/transaction" - "github.com/nspcc-dev/neo-go/pkg/internal/testserdes" "github.com/stretchr/testify/assert" ) diff --git a/pkg/network/payload/inventory_test.go b/pkg/network/payload/inventory_test.go index 1fd685c40..4a15d74a9 100644 --- a/pkg/network/payload/inventory_test.go +++ b/pkg/network/payload/inventory_test.go @@ -3,8 +3,8 @@ package payload import ( "testing" + "github.com/nspcc-dev/neo-go/internal/testserdes" "github.com/nspcc-dev/neo-go/pkg/crypto/hash" - "github.com/nspcc-dev/neo-go/pkg/internal/testserdes" . "github.com/nspcc-dev/neo-go/pkg/util" "github.com/stretchr/testify/assert" ) diff --git a/pkg/network/payload/merkleblock_test.go b/pkg/network/payload/merkleblock_test.go index 30362bb40..5483fb6b2 100644 --- a/pkg/network/payload/merkleblock_test.go +++ b/pkg/network/payload/merkleblock_test.go @@ -6,10 +6,10 @@ import ( "github.com/stretchr/testify/require" + "github.com/nspcc-dev/neo-go/internal/testserdes" "github.com/nspcc-dev/neo-go/pkg/core/block" "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/internal/testserdes" "github.com/nspcc-dev/neo-go/pkg/util" ) diff --git a/pkg/network/payload/ping_test.go b/pkg/network/payload/ping_test.go index 82b28ed67..84a0b2172 100644 --- a/pkg/network/payload/ping_test.go +++ b/pkg/network/payload/ping_test.go @@ -3,7 +3,7 @@ package payload import ( "testing" - "github.com/nspcc-dev/neo-go/pkg/internal/testserdes" + "github.com/nspcc-dev/neo-go/internal/testserdes" "github.com/stretchr/testify/assert" ) diff --git a/pkg/network/payload/version_test.go b/pkg/network/payload/version_test.go index 405b4cead..e0bac2538 100644 --- a/pkg/network/payload/version_test.go +++ b/pkg/network/payload/version_test.go @@ -3,8 +3,8 @@ package payload import ( "testing" + "github.com/nspcc-dev/neo-go/internal/testserdes" "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/network/capability" "github.com/stretchr/testify/assert" ) diff --git a/pkg/rpc/client/rpc_test.go b/pkg/rpc/client/rpc_test.go index 7242eb9de..1f461d7bc 100644 --- a/pkg/rpc/client/rpc_test.go +++ b/pkg/rpc/client/rpc_test.go @@ -14,6 +14,7 @@ import ( "time" "github.com/gorilla/websocket" + "github.com/nspcc-dev/neo-go/internal/testserdes" "github.com/nspcc-dev/neo-go/pkg/config/netmode" "github.com/nspcc-dev/neo-go/pkg/core/block" "github.com/nspcc-dev/neo-go/pkg/core/state" @@ -21,7 +22,6 @@ import ( "github.com/nspcc-dev/neo-go/pkg/crypto/hash" "github.com/nspcc-dev/neo-go/pkg/crypto/keys" "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/rpc/request" "github.com/nspcc-dev/neo-go/pkg/rpc/response/result" "github.com/nspcc-dev/neo-go/pkg/smartcontract" diff --git a/pkg/rpc/response/result/mpt_test.go b/pkg/rpc/response/result/mpt_test.go index 22e0c021c..0db0bbc69 100644 --- a/pkg/rpc/response/result/mpt_test.go +++ b/pkg/rpc/response/result/mpt_test.go @@ -4,9 +4,9 @@ import ( "encoding/json" "testing" + "github.com/nspcc-dev/neo-go/internal/random" + "github.com/nspcc-dev/neo-go/internal/testserdes" "github.com/nspcc-dev/neo-go/pkg/core/mpt" - "github.com/nspcc-dev/neo-go/pkg/internal/random" - "github.com/nspcc-dev/neo-go/pkg/internal/testserdes" "github.com/nspcc-dev/neo-go/pkg/io" "github.com/stretchr/testify/require" ) diff --git a/pkg/rpc/server/client_test.go b/pkg/rpc/server/client_test.go index a56e82434..31467f76e 100644 --- a/pkg/rpc/server/client_test.go +++ b/pkg/rpc/server/client_test.go @@ -5,11 +5,11 @@ import ( "encoding/hex" "testing" + "github.com/nspcc-dev/neo-go/internal/testchain" "github.com/nspcc-dev/neo-go/pkg/core/fee" "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/crypto/keys" - "github.com/nspcc-dev/neo-go/pkg/internal/testchain" "github.com/nspcc-dev/neo-go/pkg/io" "github.com/nspcc-dev/neo-go/pkg/rpc/client" "github.com/nspcc-dev/neo-go/pkg/smartcontract" diff --git a/pkg/rpc/server/server_test.go b/pkg/rpc/server/server_test.go index d330c7ac0..1d6008eca 100644 --- a/pkg/rpc/server/server_test.go +++ b/pkg/rpc/server/server_test.go @@ -18,14 +18,14 @@ import ( "time" "github.com/gorilla/websocket" + "github.com/nspcc-dev/neo-go/internal/testchain" + "github.com/nspcc-dev/neo-go/internal/testserdes" "github.com/nspcc-dev/neo-go/pkg/core" "github.com/nspcc-dev/neo-go/pkg/core/block" "github.com/nspcc-dev/neo-go/pkg/core/fee" "github.com/nspcc-dev/neo-go/pkg/core/state" "github.com/nspcc-dev/neo-go/pkg/core/transaction" "github.com/nspcc-dev/neo-go/pkg/encoding/address" - "github.com/nspcc-dev/neo-go/pkg/internal/testchain" - "github.com/nspcc-dev/neo-go/pkg/internal/testserdes" "github.com/nspcc-dev/neo-go/pkg/io" "github.com/nspcc-dev/neo-go/pkg/rpc/response" "github.com/nspcc-dev/neo-go/pkg/rpc/response/result" diff --git a/pkg/rpc/server/subscription_test.go b/pkg/rpc/server/subscription_test.go index c7ab570c7..55800466e 100644 --- a/pkg/rpc/server/subscription_test.go +++ b/pkg/rpc/server/subscription_test.go @@ -8,9 +8,9 @@ import ( "time" "github.com/gorilla/websocket" + "github.com/nspcc-dev/neo-go/internal/testchain" "github.com/nspcc-dev/neo-go/pkg/core" "github.com/nspcc-dev/neo-go/pkg/encoding/address" - "github.com/nspcc-dev/neo-go/pkg/internal/testchain" "github.com/nspcc-dev/neo-go/pkg/rpc/response" "github.com/stretchr/testify/require" "go.uber.org/atomic" diff --git a/pkg/smartcontract/context/context_test.go b/pkg/smartcontract/context/context_test.go index 302b5cda9..8c389e97c 100644 --- a/pkg/smartcontract/context/context_test.go +++ b/pkg/smartcontract/context/context_test.go @@ -4,12 +4,12 @@ import ( "encoding/hex" "testing" + "github.com/nspcc-dev/neo-go/internal/testserdes" "github.com/nspcc-dev/neo-go/pkg/config/netmode" "github.com/nspcc-dev/neo-go/pkg/core/interop" "github.com/nspcc-dev/neo-go/pkg/core/interop/crypto" "github.com/nspcc-dev/neo-go/pkg/core/transaction" "github.com/nspcc-dev/neo-go/pkg/crypto/keys" - "github.com/nspcc-dev/neo-go/pkg/internal/testserdes" "github.com/nspcc-dev/neo-go/pkg/smartcontract" "github.com/nspcc-dev/neo-go/pkg/util" "github.com/nspcc-dev/neo-go/pkg/vm" diff --git a/pkg/smartcontract/context/item_test.go b/pkg/smartcontract/context/item_test.go index c466ed156..ca29fc897 100644 --- a/pkg/smartcontract/context/item_test.go +++ b/pkg/smartcontract/context/item_test.go @@ -4,9 +4,9 @@ import ( "encoding/hex" "testing" + "github.com/nspcc-dev/neo-go/internal/random" + "github.com/nspcc-dev/neo-go/internal/testserdes" "github.com/nspcc-dev/neo-go/pkg/crypto/keys" - "github.com/nspcc-dev/neo-go/pkg/internal/random" - "github.com/nspcc-dev/neo-go/pkg/internal/testserdes" "github.com/nspcc-dev/neo-go/pkg/smartcontract" "github.com/nspcc-dev/neo-go/pkg/util" "github.com/stretchr/testify/require" diff --git a/pkg/smartcontract/manifest/container_test.go b/pkg/smartcontract/manifest/container_test.go index fd5325737..c8f8679fd 100644 --- a/pkg/smartcontract/manifest/container_test.go +++ b/pkg/smartcontract/manifest/container_test.go @@ -4,8 +4,8 @@ import ( "encoding/json" "testing" - "github.com/nspcc-dev/neo-go/pkg/internal/random" - "github.com/nspcc-dev/neo-go/pkg/internal/testserdes" + "github.com/nspcc-dev/neo-go/internal/random" + "github.com/nspcc-dev/neo-go/internal/testserdes" "github.com/nspcc-dev/neo-go/pkg/util" "github.com/stretchr/testify/require" ) diff --git a/pkg/smartcontract/manifest/permission_test.go b/pkg/smartcontract/manifest/permission_test.go index 1e3e4f8e3..8a7b05a74 100644 --- a/pkg/smartcontract/manifest/permission_test.go +++ b/pkg/smartcontract/manifest/permission_test.go @@ -5,8 +5,8 @@ import ( "fmt" "testing" + "github.com/nspcc-dev/neo-go/internal/random" "github.com/nspcc-dev/neo-go/pkg/crypto/keys" - "github.com/nspcc-dev/neo-go/pkg/internal/random" "github.com/nspcc-dev/neo-go/pkg/util" "github.com/stretchr/testify/require" ) diff --git a/pkg/smartcontract/nef/nef_test.go b/pkg/smartcontract/nef/nef_test.go index a2c0a119c..01ecc2b00 100644 --- a/pkg/smartcontract/nef/nef_test.go +++ b/pkg/smartcontract/nef/nef_test.go @@ -3,8 +3,8 @@ package nef import ( "testing" + "github.com/nspcc-dev/neo-go/internal/testserdes" "github.com/nspcc-dev/neo-go/pkg/crypto/hash" - "github.com/nspcc-dev/neo-go/pkg/internal/testserdes" "github.com/nspcc-dev/neo-go/pkg/util" "github.com/stretchr/testify/require" ) diff --git a/pkg/smartcontract/parameter_test.go b/pkg/smartcontract/parameter_test.go index 8a9481f9e..0a9c49251 100644 --- a/pkg/smartcontract/parameter_test.go +++ b/pkg/smartcontract/parameter_test.go @@ -8,7 +8,7 @@ import ( "reflect" "testing" - "github.com/nspcc-dev/neo-go/pkg/internal/testserdes" + "github.com/nspcc-dev/neo-go/internal/testserdes" "github.com/nspcc-dev/neo-go/pkg/util" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" diff --git a/pkg/util/fixed8_test.go b/pkg/util/fixed8_test.go index cd097c9b5..8421b11fc 100644 --- a/pkg/util/fixed8_test.go +++ b/pkg/util/fixed8_test.go @@ -6,7 +6,7 @@ import ( "strconv" "testing" - "github.com/nspcc-dev/neo-go/pkg/internal/testserdes" + "github.com/nspcc-dev/neo-go/internal/testserdes" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" "gopkg.in/yaml.v2" diff --git a/pkg/util/uint160_test.go b/pkg/util/uint160_test.go index c72b58633..7445242b1 100644 --- a/pkg/util/uint160_test.go +++ b/pkg/util/uint160_test.go @@ -4,7 +4,7 @@ import ( "encoding/hex" "testing" - "github.com/nspcc-dev/neo-go/pkg/internal/testserdes" + "github.com/nspcc-dev/neo-go/internal/testserdes" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" ) diff --git a/pkg/util/uint256_test.go b/pkg/util/uint256_test.go index fbe995243..e0e3d2291 100644 --- a/pkg/util/uint256_test.go +++ b/pkg/util/uint256_test.go @@ -4,7 +4,7 @@ import ( "encoding/hex" "testing" - "github.com/nspcc-dev/neo-go/pkg/internal/testserdes" + "github.com/nspcc-dev/neo-go/internal/testserdes" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" ) diff --git a/pkg/vm/vm_test.go b/pkg/vm/vm_test.go index 5088171e4..046bc9548 100644 --- a/pkg/vm/vm_test.go +++ b/pkg/vm/vm_test.go @@ -10,9 +10,9 @@ import ( "math/rand" "testing" + "github.com/nspcc-dev/neo-go/internal/random" "github.com/nspcc-dev/neo-go/pkg/core/interop/interopnames" "github.com/nspcc-dev/neo-go/pkg/encoding/bigint" - "github.com/nspcc-dev/neo-go/pkg/internal/random" "github.com/nspcc-dev/neo-go/pkg/io" "github.com/nspcc-dev/neo-go/pkg/smartcontract" "github.com/nspcc-dev/neo-go/pkg/vm/emit" diff --git a/pkg/wallet/account_test.go b/pkg/wallet/account_test.go index 84225b413..f44eeb6ef 100644 --- a/pkg/wallet/account_test.go +++ b/pkg/wallet/account_test.go @@ -5,9 +5,9 @@ import ( "encoding/json" "testing" + "github.com/nspcc-dev/neo-go/internal/keytestcases" "github.com/nspcc-dev/neo-go/pkg/crypto/hash" "github.com/nspcc-dev/neo-go/pkg/crypto/keys" - "github.com/nspcc-dev/neo-go/pkg/internal/keytestcases" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" ) From 966b50f2aeb9f3eec8181f1fbc8a619f0ba808a1 Mon Sep 17 00:00:00 2001 From: Evgenii Stratonikov Date: Mon, 23 Nov 2020 16:24:47 +0300 Subject: [PATCH 2/4] core: save StateRootInHeader in genesis block --- pkg/core/util.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pkg/core/util.go b/pkg/core/util.go index 05c1ce495..eb85640b6 100644 --- a/pkg/core/util.go +++ b/pkg/core/util.go @@ -51,7 +51,8 @@ func createGenesisBlock(cfg config.ProtocolConfiguration) (*block.Block, error) InvocationScript: []byte{}, VerificationScript: []byte{byte(opcode.PUSH1)}, }, - Network: cfg.Magic, + StateRootEnabled: cfg.StateRootInHeader, + Network: cfg.Magic, } b := &block.Block{ From 6f7284906aad5808028cccddcd5bd41771da2a01 Mon Sep 17 00:00:00 2001 From: Evgenii Stratonikov Date: Tue, 24 Nov 2020 11:36:09 +0300 Subject: [PATCH 3/4] blockchainer: allow to dump/restore chain --- cli/server/server.go | 75 ++++++++++++-------------------- pkg/core/blockchain_test.go | 61 ++++++++++++++++++++++++++ pkg/core/chaindump/dump.go | 77 +++++++++++++++++++++++++++++++++ pkg/core/helper_test.go | 86 ++++++++++++++++++------------------- 4 files changed, 208 insertions(+), 91 deletions(-) create mode 100644 pkg/core/chaindump/dump.go diff --git a/cli/server/server.go b/cli/server/server.go index ff538269c..bd4c3f973 100644 --- a/cli/server/server.go +++ b/cli/server/server.go @@ -10,6 +10,7 @@ import ( "github.com/nspcc-dev/neo-go/pkg/config" "github.com/nspcc-dev/neo-go/pkg/core" "github.com/nspcc-dev/neo-go/pkg/core/block" + "github.com/nspcc-dev/neo-go/pkg/core/chaindump" "github.com/nspcc-dev/neo-go/pkg/core/storage" "github.com/nspcc-dev/neo-go/pkg/io" "github.com/nspcc-dev/neo-go/pkg/network" @@ -193,20 +194,9 @@ func dumpDB(ctx *cli.Context) error { count = chainCount - start } writer.WriteU32LE(count) - for i := start; i < start+count; i++ { - bh := chain.GetHeaderHash(int(i)) - b, err := chain.GetBlock(bh) - if err != nil { - return cli.NewExitError(fmt.Errorf("failed to get block %d: %w", i, err), 1) - } - buf := io.NewBufBinWriter() - b.EncodeBinary(buf.BinWriter) - bytes := buf.Bytes() - writer.WriteU32LE(uint32(len(bytes))) - writer.WriteBytes(bytes) - if writer.Err != nil { - return cli.NewExitError(err, 1) - } + err = chaindump.Dump(chain, writer, start, count) + if err != nil { + return cli.NewExitError(err.Error(), 1) } pprof.ShutDown() prometheus.ShutDown() @@ -259,13 +249,6 @@ func restoreDB(ctx *cli.Context) error { if count == 0 { count = allBlocks - skip } - i := uint32(0) - for ; i < skip; i++ { - _, err := readBlock(reader) - if err != nil { - return cli.NewExitError(err, 1) - } - } gctx := newGraceContext() var lastIndex uint32 @@ -274,45 +257,41 @@ func restoreDB(ctx *cli.Context) error { _ = dump.tryPersist(dumpDir, lastIndex) }() - for ; i < skip+count; i++ { + var f = func(b *block.Block) error { select { case <-gctx.Done(): - return cli.NewExitError("cancelled", 1) + return gctx.Err() default: + return nil } - bytes, err := readBlock(reader) - block := block.New(cfg.ProtocolConfiguration.Magic, cfg.ProtocolConfiguration.StateRootInHeader) - newReader := io.NewBinReaderFromBuf(bytes) - block.DecodeBinary(newReader) - if err != nil { - return cli.NewExitError(err, 1) - } - if block.Index == 0 && i == 0 && skip == 0 { - genesis, err := chain.GetBlock(block.Hash()) - if err == nil && genesis.Index == 0 { - log.Info("skipped genesis block", zap.String("hash", block.Hash().StringLE())) + } + if dumpDir != "" { + f = func(b *block.Block) error { + select { + case <-gctx.Done(): + return gctx.Err() + default: } - } else { - err = chain.AddBlock(block) - if err != nil { - return cli.NewExitError(fmt.Errorf("failed to add block %d: %w", i, err), 1) - } - } - if dumpDir != "" { batch := chain.LastBatch() // The genesis block may already be persisted, so LastBatch() will return nil. - if batch == nil && block.Index == 0 { - continue + if batch == nil && b.Index == 0 { + return nil } - dump.add(block.Index, batch) - lastIndex = block.Index - if block.Index%1000 == 0 { - if err := dump.tryPersist(dumpDir, block.Index); err != nil { - return cli.NewExitError(fmt.Errorf("can't dump storage to file: %w", err), 1) + dump.add(b.Index, batch) + lastIndex = b.Index + if b.Index%1000 == 0 { + if err := dump.tryPersist(dumpDir, b.Index); err != nil { + return fmt.Errorf("can't dump storage to file: %w", err) } } + return nil } } + + err = chaindump.Restore(chain, reader, skip, count, f) + if err != nil { + return cli.NewExitError(err, 1) + } return nil } diff --git a/pkg/core/blockchain_test.go b/pkg/core/blockchain_test.go index cd7f37d8b..e70577a9d 100644 --- a/pkg/core/blockchain_test.go +++ b/pkg/core/blockchain_test.go @@ -11,6 +11,7 @@ import ( "github.com/nspcc-dev/neo-go/internal/testchain" "github.com/nspcc-dev/neo-go/pkg/config/netmode" "github.com/nspcc-dev/neo-go/pkg/core/block" + "github.com/nspcc-dev/neo-go/pkg/core/chaindump" "github.com/nspcc-dev/neo-go/pkg/core/fee" "github.com/nspcc-dev/neo-go/pkg/core/interop/interopnames" "github.com/nspcc-dev/neo-go/pkg/core/mempool" @@ -1032,3 +1033,63 @@ func TestSubscriptions(t *testing.T) { _, err = bc.genBlocks(2 * chBufSize) require.NoError(t, err) } + +func testDumpAndRestore(t *testing.T, stateRootInHeader bool) { + bc := newTestChainWithStateRoot(t, stateRootInHeader) + defer bc.Close() + + initBasicChain(t, bc) + require.True(t, bc.BlockHeight() > 5) // ensure that test is valid + + w := io.NewBufBinWriter() + require.NoError(t, chaindump.Dump(bc, w.BinWriter, 0, bc.BlockHeight()+1)) + require.NoError(t, w.Err) + + buf := w.Bytes() + t.Run("invalid start", func(t *testing.T) { + bc2 := newTestChainWithStateRoot(t, stateRootInHeader) + defer bc2.Close() + + r := io.NewBinReaderFromBuf(buf) + require.Error(t, chaindump.Restore(bc2, r, 2, 1, nil)) + }) + t.Run("good", func(t *testing.T) { + bc2 := newTestChainWithStateRoot(t, stateRootInHeader) + defer bc2.Close() + + r := io.NewBinReaderFromBuf(buf) + require.NoError(t, chaindump.Restore(bc2, r, 0, 2, nil)) + require.Equal(t, uint32(1), bc2.BlockHeight()) + + r = io.NewBinReaderFromBuf(buf) // new reader because start is relative to dump + require.NoError(t, chaindump.Restore(bc2, r, 2, 1, nil)) + t.Run("check handler", func(t *testing.T) { + lastIndex := uint32(0) + errStopped := errors.New("stopped") + f := func(b *block.Block) error { + lastIndex = b.Index + if b.Index >= bc.BlockHeight()-1 { + return errStopped + } + return nil + } + require.NoError(t, chaindump.Restore(bc2, r, 0, 1, f)) + require.Equal(t, bc2.BlockHeight(), lastIndex) + + r = io.NewBinReaderFromBuf(buf) + err := chaindump.Restore(bc2, r, 4, bc.BlockHeight()-bc2.BlockHeight(), f) + require.True(t, errors.Is(err, errStopped)) + require.Equal(t, bc.BlockHeight()-1, lastIndex) + }) + }) + +} + +func TestDumpAndRestore(t *testing.T) { + t.Run("no state root", func(t *testing.T) { + testDumpAndRestore(t, false) + }) + t.Run("with state root", func(t *testing.T) { + testDumpAndRestore(t, true) + }) +} diff --git a/pkg/core/chaindump/dump.go b/pkg/core/chaindump/dump.go new file mode 100644 index 000000000..9fc9e6649 --- /dev/null +++ b/pkg/core/chaindump/dump.go @@ -0,0 +1,77 @@ +package chaindump + +import ( + "fmt" + + "github.com/nspcc-dev/neo-go/pkg/core/block" + "github.com/nspcc-dev/neo-go/pkg/core/blockchainer" + "github.com/nspcc-dev/neo-go/pkg/io" +) + +// Dump writes count blocks from start to the provided writer. +// Note: header needs to be written separately by client. +func Dump(bc blockchainer.Blockchainer, w *io.BinWriter, start, count uint32) error { + for i := start; i < start+count; i++ { + bh := bc.GetHeaderHash(int(i)) + b, err := bc.GetBlock(bh) + if err != nil { + return err + } + buf := io.NewBufBinWriter() + b.EncodeBinary(buf.BinWriter) + bytes := buf.Bytes() + w.WriteU32LE(uint32(len(bytes))) + w.WriteBytes(bytes) + if w.Err != nil { + return w.Err + } + } + return nil +} + +// Restore restores blocks from provided reader. +// f is called after addition of every block. +func Restore(bc blockchainer.Blockchainer, r *io.BinReader, skip, count uint32, f func(b *block.Block) error) error { + readBlock := func(r *io.BinReader) ([]byte, error) { + var size = r.ReadU32LE() + buf := make([]byte, size) + r.ReadBytes(buf) + return buf, r.Err + } + + i := uint32(0) + for ; i < skip; i++ { + _, err := readBlock(r) + if err != nil { + return err + } + } + + magic := bc.GetConfig().Magic + stateRootInHeader := bc.GetConfig().StateRootInHeader + + for ; i < skip+count; i++ { + buf, err := readBlock(r) + if err != nil { + return err + } + b := block.New(magic, stateRootInHeader) + r := io.NewBinReaderFromBuf(buf) + b.DecodeBinary(r) + if r.Err != nil { + return r.Err + } + if b.Index != 0 || i != 0 || skip != 0 { + err = bc.AddBlock(b) + if err != nil { + return fmt.Errorf("failed to add block %d: %w", i, err) + } + } + if f != nil { + if err := f(b); err != nil { + return err + } + } + } + return nil +} diff --git a/pkg/core/helper_test.go b/pkg/core/helper_test.go index 0af065e3d..eac68e24d 100644 --- a/pkg/core/helper_test.go +++ b/pkg/core/helper_test.go @@ -16,6 +16,7 @@ import ( "github.com/nspcc-dev/neo-go/pkg/compiler" "github.com/nspcc-dev/neo-go/pkg/config" "github.com/nspcc-dev/neo-go/pkg/core/block" + "github.com/nspcc-dev/neo-go/pkg/core/chaindump" "github.com/nspcc-dev/neo-go/pkg/core/fee" "github.com/nspcc-dev/neo-go/pkg/core/interop/interopnames" "github.com/nspcc-dev/neo-go/pkg/core/native" @@ -171,10 +172,49 @@ func newDumbBlock() *block.Block { func TestCreateBasicChain(t *testing.T) { const saveChain = false const prefix = "../rpc/server/testdata/" - // To make enough GAS. - const numOfEmptyBlocks = 200 + + bc := newTestChain(t) + defer bc.Close() + initBasicChain(t, bc) + + if saveChain { + outStream, err := os.Create(prefix + "testblocks.acc") + require.NoError(t, err) + defer outStream.Close() + + writer := io.NewBinWriterFromIO(outStream) + writer.WriteU32LE(bc.BlockHeight()) + err = chaindump.Dump(bc, writer, 1, bc.BlockHeight()) + require.NoError(t, err) + } + + priv0 := testchain.PrivateKeyByID(0) + priv1 := testchain.PrivateKeyByID(1) + priv0ScriptHash := priv0.GetScriptHash() + acc0, err := wallet.NewAccountFromWIF(priv0.WIF()) + require.NoError(t, err) + + // Prepare some transaction for future submission. + txSendRaw := newNEP17Transfer(bc.contracts.NEO.Hash, priv0ScriptHash, priv1.GetScriptHash(), int64(util.Fixed8FromInt64(1000))) + txSendRaw.ValidUntilBlock = transaction.MaxValidUntilBlockIncrement + txSendRaw.Nonce = 0x1234 + txSendRaw.Signers = []transaction.Signer{{ + Account: priv0ScriptHash, + Scopes: transaction.CalledByEntry, + AllowedContracts: nil, + AllowedGroups: nil, + }} + require.NoError(t, addNetworkFee(bc, txSendRaw, acc0)) + require.NoError(t, acc0.SignTx(txSendRaw)) + bw := io.NewBufBinWriter() + txSendRaw.EncodeBinary(bw.BinWriter) + t.Logf("sendrawtransaction: %s", hex.EncodeToString(bw.Bytes())) +} + +func initBasicChain(t *testing.T, bc *Blockchain) { + const prefix = "../rpc/server/testdata/" // Increase in case if you need more blocks - const validUntilBlock = numOfEmptyBlocks + 1000 + const validUntilBlock = 1200 // To be incremented after each created transaction to keep chain constant. var testNonce uint32 = 1 @@ -186,8 +226,6 @@ func TestCreateBasicChain(t *testing.T) { } const neoAmount = 99999000 - bc := newTestChain(t) - defer bc.Close() gasHash := bc.contracts.GAS.Hash neoHash := bc.contracts.NEO.Hash @@ -340,44 +378,6 @@ func TestCreateBasicChain(t *testing.T) { require.NoError(t, acc0.SignTx(txDeploy2)) b = bc.newBlock(txDeploy2) require.NoError(t, bc.AddBlock(b)) - - if saveChain { - outStream, err := os.Create(prefix + "testblocks.acc") - require.NoError(t, err) - defer outStream.Close() - - writer := io.NewBinWriterFromIO(outStream) - - count := bc.BlockHeight() + 1 - writer.WriteU32LE(count - 1) - - for i := 1; i < int(count); i++ { - bh := bc.GetHeaderHash(i) - b, err := bc.GetBlock(bh) - require.NoError(t, err) - bytes, err := testserdes.EncodeBinary(b) - require.NoError(t, err) - writer.WriteU32LE(uint32(len(bytes))) - writer.WriteBytes(bytes) - require.NoError(t, writer.Err) - } - } - - // Prepare some transaction for future submission. - txSendRaw := newNEP17Transfer(neoHash, priv0ScriptHash, priv1.GetScriptHash(), int64(util.Fixed8FromInt64(1000))) - txSendRaw.ValidUntilBlock = validUntilBlock - txSendRaw.Nonce = getNextNonce() - txSendRaw.Signers = []transaction.Signer{{ - Account: priv0ScriptHash, - Scopes: transaction.CalledByEntry, - AllowedContracts: nil, - AllowedGroups: nil, - }} - require.NoError(t, addNetworkFee(bc, txSendRaw, acc0)) - require.NoError(t, acc0.SignTx(txSendRaw)) - bw = io.NewBufBinWriter() - txSendRaw.EncodeBinary(bw.BinWriter) - t.Logf("sendrawtransaction: %s", hex.EncodeToString(bw.Bytes())) } func newNEP17Transfer(sc, from, to util.Uint160, amount int64) *transaction.Transaction { From 67f26859a88edb201d1c6fa422b3fbeecf92d2bb Mon Sep 17 00:00:00 2001 From: Evgenii Stratonikov Date: Mon, 23 Nov 2020 14:09:45 +0300 Subject: [PATCH 4/4] scripts: implement script for creating dumps This is useful for creating dumps providing various load to benchmark restore or check compatibility with C# nodes. Related #1472. --- internal/testchain/transaction.go | 88 ++++++++++++++ pkg/core/blockchain_test.go | 22 ++-- pkg/core/helper_test.go | 63 ++-------- pkg/core/native_contract_test.go | 9 +- pkg/core/native_designate_test.go | 4 +- pkg/core/native_neo_test.go | 4 +- pkg/core/native_oracle_test.go | 2 +- pkg/core/native_policy_test.go | 3 +- scripts/gendump/main.go | 193 ++++++++++++++++++++++++++++++ 9 files changed, 312 insertions(+), 76 deletions(-) create mode 100644 internal/testchain/transaction.go create mode 100644 scripts/gendump/main.go diff --git a/internal/testchain/transaction.go b/internal/testchain/transaction.go new file mode 100644 index 000000000..d2a37a134 --- /dev/null +++ b/internal/testchain/transaction.go @@ -0,0 +1,88 @@ +package testchain + +import ( + "encoding/json" + gio "io" + + "github.com/nspcc-dev/neo-go/pkg/compiler" + "github.com/nspcc-dev/neo-go/pkg/config/netmode" + "github.com/nspcc-dev/neo-go/pkg/core/blockchainer" + "github.com/nspcc-dev/neo-go/pkg/core/fee" + "github.com/nspcc-dev/neo-go/pkg/core/interop/interopnames" + "github.com/nspcc-dev/neo-go/pkg/core/native" + "github.com/nspcc-dev/neo-go/pkg/core/transaction" + "github.com/nspcc-dev/neo-go/pkg/io" + "github.com/nspcc-dev/neo-go/pkg/util" + "github.com/nspcc-dev/neo-go/pkg/vm/emit" + "github.com/nspcc-dev/neo-go/pkg/vm/opcode" +) + +var ( + ownerHash = MultisigScriptHash() + ownerScript = MultisigVerificationScript() +) + +// NewTransferFromOwner returns transaction transfering funds from NEO and GAS owner. +func NewTransferFromOwner(bc blockchainer.Blockchainer, contractHash, to util.Uint160, amount int64, + nonce, validUntil uint32) (*transaction.Transaction, error) { + w := io.NewBufBinWriter() + emit.AppCallWithOperationAndArgs(w.BinWriter, contractHash, "transfer", ownerHash, to, amount, nil) + emit.Opcodes(w.BinWriter, opcode.ASSERT) + if w.Err != nil { + return nil, w.Err + } + + script := w.Bytes() + tx := transaction.New(netmode.UnitTestNet, script, 10000000) + tx.ValidUntilBlock = validUntil + tx.Nonce = nonce + tx.Signers = []transaction.Signer{{ + Account: ownerHash, + Scopes: transaction.CalledByEntry, + AllowedContracts: nil, + AllowedGroups: nil, + }} + return tx, SignTx(bc, tx) +} + +// NewDeployTx returns new deployment tx for contract with name with Go code read from r. +func NewDeployTx(name string, r gio.Reader) (*transaction.Transaction, []byte, error) { + avm, di, err := compiler.CompileWithDebugInfo(name, r) + if err != nil { + return nil, nil, err + } + + w := io.NewBufBinWriter() + m, err := di.ConvertToManifest(name, nil) + if err != nil { + return nil, nil, err + } + bs, err := json.Marshal(m) + if err != nil { + return nil, nil, err + } + emit.Bytes(w.BinWriter, bs) + emit.Bytes(w.BinWriter, avm) + emit.Syscall(w.BinWriter, interopnames.SystemContractCreate) + if w.Err != nil { + return nil, nil, err + } + return transaction.New(Network(), w.Bytes(), 100*native.GASFactor), avm, nil +} + +// SignTx signs provided transactions with validator keys. +func SignTx(bc blockchainer.Blockchainer, txs ...*transaction.Transaction) error { + for _, tx := range txs { + size := io.GetVarSize(tx) + netFee, sizeDelta := fee.Calculate(ownerScript) + tx.NetworkFee += netFee + size += sizeDelta + tx.NetworkFee += int64(size) * bc.FeePerByte() + data := tx.GetSignedPart() + tx.Scripts = []transaction.Witness{{ + InvocationScript: Sign(data), + VerificationScript: ownerScript, + }} + } + return nil +} diff --git a/pkg/core/blockchain_test.go b/pkg/core/blockchain_test.go index e70577a9d..d9dfa0e85 100644 --- a/pkg/core/blockchain_test.go +++ b/pkg/core/blockchain_test.go @@ -133,7 +133,7 @@ func TestAddBlockStateRoot(t *testing.T) { tx := newNEP17Transfer(bc.contracts.NEO.Hash, neoOwner, util.Uint160{}, 1) tx.ValidUntilBlock = bc.BlockHeight() + 1 addSigners(tx) - require.NoError(t, signTx(bc, tx)) + require.NoError(t, testchain.SignTx(bc, tx)) lastBlock := bc.topBlock.Load().(*block.Block) b := newBlock(bc.config, lastBlock.Index+1, lastBlock.Hash(), tx) @@ -159,7 +159,7 @@ func TestAddBadBlock(t *testing.T) { Account: testchain.MultisigScriptHash(), Scopes: transaction.None, }} - require.NoError(t, signTx(bc, tx)) + require.NoError(t, testchain.SignTx(bc, tx)) b1 := bc.newBlock(tx) require.Error(t, bc.AddBlock(b1)) @@ -179,7 +179,7 @@ func TestAddBadBlock(t *testing.T) { Account: testchain.MultisigScriptHash(), Scopes: transaction.None, }} - require.NoError(t, signTx(bc, tx)) + require.NoError(t, testchain.SignTx(bc, tx)) require.NoError(t, bc.PoolTx(tx)) bc.config.VerifyTransactions = true bc.config.VerifyBlocks = true @@ -192,7 +192,7 @@ func TestGetHeader(t *testing.T) { tx := transaction.New(netmode.UnitTestNet, []byte{byte(opcode.PUSH1)}, 0) tx.ValidUntilBlock = bc.BlockHeight() + 1 addSigners(tx) - assert.Nil(t, signTx(bc, tx)) + assert.Nil(t, testchain.SignTx(bc, tx)) block := bc.newBlock(tx) err := bc.AddBlock(block) assert.Nil(t, err) @@ -277,7 +277,7 @@ func TestVerifyTx(t *testing.T) { txMove := bc.newTestTx(neoOwner, w.Bytes()) txMove.SystemFee = 1_000_000_000 - require.NoError(t, signTx(bc, txMove)) + require.NoError(t, testchain.SignTx(bc, txMove)) b := bc.newBlock(txMove) require.NoError(t, bc.AddBlock(b)) @@ -805,12 +805,12 @@ func TestMemPoolRemoval(t *testing.T) { notAddedTxes := make([]*transaction.Transaction, notAdded) for i := range addedTxes { addedTxes[i] = bc.newTestTx(testchain.MultisigScriptHash(), []byte{byte(opcode.PUSH1)}) - require.NoError(t, signTx(bc, addedTxes[i])) + require.NoError(t, testchain.SignTx(bc, addedTxes[i])) require.NoError(t, bc.PoolTx(addedTxes[i])) } for i := range notAddedTxes { notAddedTxes[i] = bc.newTestTx(testchain.MultisigScriptHash(), []byte{byte(opcode.PUSH1)}) - require.NoError(t, signTx(bc, notAddedTxes[i])) + require.NoError(t, testchain.SignTx(bc, notAddedTxes[i])) require.NoError(t, bc.PoolTx(notAddedTxes[i])) } b := bc.newBlock(addedTxes...) @@ -854,7 +854,7 @@ func TestGetTransaction(t *testing.T) { Account: testchain.MultisigScriptHash(), Scopes: transaction.CalledByEntry, }} - require.NoError(t, signTx(bc, tx1, tx2)) + require.NoError(t, testchain.SignTx(bc, tx1, tx2)) b1 := bc.newBlock(tx1) assert.Nil(t, bc.AddBlock(b1)) @@ -955,7 +955,7 @@ func TestSubscriptions(t *testing.T) { txGood1.Signers = []transaction.Signer{{Account: neoOwner}} txGood1.Nonce = 1 txGood1.ValidUntilBlock = 1024 - require.NoError(t, signTx(bc, txGood1)) + require.NoError(t, testchain.SignTx(bc, txGood1)) // Reset() reuses the script buffer and we need to keep scripts. script = io.NewBufBinWriter() @@ -967,7 +967,7 @@ func TestSubscriptions(t *testing.T) { txBad.Signers = []transaction.Signer{{Account: neoOwner}} txBad.Nonce = 2 txBad.ValidUntilBlock = 1024 - require.NoError(t, signTx(bc, txBad)) + require.NoError(t, testchain.SignTx(bc, txBad)) script = io.NewBufBinWriter() emit.Bytes(script.BinWriter, []byte("yay! yay! yay!")) @@ -977,7 +977,7 @@ func TestSubscriptions(t *testing.T) { txGood2.Signers = []transaction.Signer{{Account: neoOwner}} txGood2.Nonce = 3 txGood2.ValidUntilBlock = 1024 - require.NoError(t, signTx(bc, txGood2)) + require.NoError(t, testchain.SignTx(bc, txGood2)) invBlock := newBlock(bc.config, bc.BlockHeight()+1, bc.CurrentHeaderHash(), txGood1, txBad, txGood2) require.NoError(t, bc.AddBlock(invBlock)) diff --git a/pkg/core/helper_test.go b/pkg/core/helper_test.go index eac68e24d..50323e3e7 100644 --- a/pkg/core/helper_test.go +++ b/pkg/core/helper_test.go @@ -13,12 +13,10 @@ import ( "github.com/nspcc-dev/neo-go/internal/testchain" "github.com/nspcc-dev/neo-go/internal/testserdes" - "github.com/nspcc-dev/neo-go/pkg/compiler" "github.com/nspcc-dev/neo-go/pkg/config" "github.com/nspcc-dev/neo-go/pkg/core/block" "github.com/nspcc-dev/neo-go/pkg/core/chaindump" "github.com/nspcc-dev/neo-go/pkg/core/fee" - "github.com/nspcc-dev/neo-go/pkg/core/interop/interopnames" "github.com/nspcc-dev/neo-go/pkg/core/native" "github.com/nspcc-dev/neo-go/pkg/core/storage" "github.com/nspcc-dev/neo-go/pkg/core/transaction" @@ -239,27 +237,13 @@ func initBasicChain(t *testing.T, bc *Blockchain) { require.Equal(t, big.NewInt(5000_0000), bc.GetUtilityTokenBalance(priv0ScriptHash)) // gas bounty // Move some NEO to one simple account. - txMoveNeo := newNEP17Transfer(neoHash, neoOwner, priv0ScriptHash, neoAmount) - txMoveNeo.ValidUntilBlock = validUntilBlock - txMoveNeo.Nonce = getNextNonce() - txMoveNeo.Signers = []transaction.Signer{{ - Account: neoOwner, - Scopes: transaction.CalledByEntry, - AllowedContracts: nil, - AllowedGroups: nil, - }} - require.NoError(t, signTx(bc, txMoveNeo)) + txMoveNeo, err := testchain.NewTransferFromOwner(bc, neoHash, priv0ScriptHash, neoAmount, getNextNonce(), validUntilBlock) + require.NoError(t, err) // Move some GAS to one simple account. - txMoveGas := newNEP17Transfer(gasHash, neoOwner, priv0ScriptHash, int64(util.Fixed8FromInt64(1000))) - txMoveGas.ValidUntilBlock = validUntilBlock - txMoveGas.Nonce = getNextNonce() - txMoveGas.Signers = []transaction.Signer{{ - Account: neoOwner, - Scopes: transaction.CalledByEntry, - AllowedContracts: nil, - AllowedGroups: nil, - }} - require.NoError(t, signTx(bc, txMoveGas)) + txMoveGas, err := testchain.NewTransferFromOwner(bc, gasHash, priv0ScriptHash, int64(util.Fixed8FromInt64(1000)), + getNextNonce(), validUntilBlock) + require.NoError(t, err) + b := bc.newBlock(txMoveNeo, txMoveGas) require.NoError(t, bc.AddBlock(b)) t.Logf("Block1 hash: %s", b.Hash().StringLE()) @@ -392,22 +376,12 @@ func newNEP17Transfer(sc, from, to util.Uint160, amount int64) *transaction.Tran func newDeployTx(t *testing.T, name, ctrName string) (*transaction.Transaction, []byte) { c, err := ioutil.ReadFile(name) require.NoError(t, err) - avm, di, err := compiler.CompileWithDebugInfo(name, bytes.NewReader(c)) + tx, avm, err := testchain.NewDeployTx(ctrName, bytes.NewReader(c)) require.NoError(t, err) t.Logf("contractHash (%s): %s", name, hash.Hash160(avm).StringLE()) t.Logf("contractScript: %x", avm) - script := io.NewBufBinWriter() - m, err := di.ConvertToManifest(ctrName, nil) - require.NoError(t, err) - bs, err := json.Marshal(m) - require.NoError(t, err) - emit.Bytes(script.BinWriter, bs) - emit.Bytes(script.BinWriter, avm) - emit.Syscall(script.BinWriter, interopnames.SystemContractCreate) - txScript := script.Bytes() - - return transaction.New(testchain.Network(), txScript, 100*native.GASFactor), avm + return tx, avm } func addSigners(txs ...*transaction.Transaction) { @@ -421,27 +395,6 @@ func addSigners(txs ...*transaction.Transaction) { } } -func signTx(bc *Blockchain, txs ...*transaction.Transaction) error { - validators := bc.GetStandByValidators() - rawScript, err := smartcontract.CreateDefaultMultiSigRedeemScript(validators) - if err != nil { - return fmt.Errorf("failed to sign tx: %w", err) - } - for _, tx := range txs { - size := io.GetVarSize(tx) - netFee, sizeDelta := fee.Calculate(rawScript) - tx.NetworkFee += netFee - size += sizeDelta - tx.NetworkFee += int64(size) * bc.FeePerByte() - data := tx.GetSignedPart() - tx.Scripts = []transaction.Witness{{ - InvocationScript: testchain.Sign(data), - VerificationScript: rawScript, - }} - } - return nil -} - func addNetworkFee(bc *Blockchain, tx *transaction.Transaction, sender *wallet.Account) error { size := io.GetVarSize(tx) netFee, sizeDelta := fee.Calculate(sender.Contract.Script) diff --git a/pkg/core/native_contract_test.go b/pkg/core/native_contract_test.go index 02dffe1d1..ac0528f91 100644 --- a/pkg/core/native_contract_test.go +++ b/pkg/core/native_contract_test.go @@ -4,6 +4,7 @@ import ( "math/big" "testing" + "github.com/nspcc-dev/neo-go/internal/testchain" "github.com/nspcc-dev/neo-go/pkg/config/netmode" "github.com/nspcc-dev/neo-go/pkg/core/dao" "github.com/nspcc-dev/neo-go/pkg/core/interop" @@ -164,13 +165,13 @@ func TestNativeContract_Invoke(t *testing.T) { validUntil := chain.blockHeight + 1 tx.ValidUntilBlock = validUntil addSigners(tx) - require.NoError(t, signTx(chain, tx)) + require.NoError(t, testchain.SignTx(chain, tx)) // Enough for Call and other opcodes, but not enough for "sum" call. tx2 := transaction.New(chain.GetConfig().Magic, script, testSumPrice*2+8000) tx2.ValidUntilBlock = chain.blockHeight + 1 addSigners(tx2) - require.NoError(t, signTx(chain, tx2)) + require.NoError(t, testchain.SignTx(chain, tx2)) b := chain.newBlock(tx, tx2) require.NoError(t, chain.AddBlock(b)) @@ -262,7 +263,7 @@ func TestNativeContract_InvokeOtherContract(t *testing.T) { validUntil := chain.blockHeight + 1 tx.ValidUntilBlock = validUntil addSigners(tx) - require.NoError(t, signTx(chain, tx)) + require.NoError(t, testchain.SignTx(chain, tx)) b := chain.newBlock(tx) require.NoError(t, chain.AddBlock(b)) @@ -289,7 +290,7 @@ func TestAllContractsHaveName(t *testing.T) { tx := transaction.New(netmode.UnitTestNet, w.Bytes(), 1015570) tx.ValidUntilBlock = bc.blockHeight + 1 addSigners(tx) - require.NoError(t, signTx(bc, tx)) + require.NoError(t, testchain.SignTx(bc, tx)) require.NoError(t, bc.AddBlock(bc.newBlock(tx))) aers, err := bc.GetAppExecResults(tx.Hash(), trigger.Application) diff --git a/pkg/core/native_designate_test.go b/pkg/core/native_designate_test.go index f29ccdb7c..4c4e78779 100644 --- a/pkg/core/native_designate_test.go +++ b/pkg/core/native_designate_test.go @@ -46,7 +46,7 @@ func (bc *Blockchain) setNodesByRole(t *testing.T, ok bool, r native.Role, nodes Scopes: transaction.CalledByEntry, }, } - require.NoError(t, signTx(bc, tx)) + require.NoError(t, testchain.SignTx(bc, tx)) tx.Scripts = append(tx.Scripts, transaction.Witness{ InvocationScript: testchain.SignCommittee(tx.GetSignedPart()), VerificationScript: testchain.CommitteeVerificationScript(), @@ -77,7 +77,7 @@ func (bc *Blockchain) getNodesByRole(t *testing.T, ok bool, r native.Role, index Scopes: transaction.None, }, } - require.NoError(t, signTx(bc, tx)) + require.NoError(t, testchain.SignTx(bc, tx)) require.NoError(t, bc.AddBlock(bc.newBlock(tx))) aer, err := bc.GetAppExecResults(tx.Hash(), trigger.Application) diff --git a/pkg/core/native_neo_test.go b/pkg/core/native_neo_test.go index fa25354e3..de83f2fc5 100644 --- a/pkg/core/native_neo_test.go +++ b/pkg/core/native_neo_test.go @@ -87,7 +87,7 @@ func TestNEO_Vote(t *testing.T) { tx := transaction.New(netmode.UnitTestNet, w.Bytes(), 1000_000_000) tx.ValidUntilBlock = bc.BlockHeight() + 1 setSigner(tx, testchain.MultisigScriptHash()) - require.NoError(t, signTx(bc, tx)) + require.NoError(t, testchain.SignTx(bc, tx)) txs = append(txs, tx) } require.NoError(t, bc.AddBlock(bc.newBlock(txs...))) @@ -318,7 +318,7 @@ func TestNEO_TransferOnPayment(t *testing.T) { tx.NetworkFee = 10_000_000 tx.ValidUntilBlock = bc.BlockHeight() + 1 addSigners(tx) - require.NoError(t, signTx(bc, tx)) + require.NoError(t, testchain.SignTx(bc, tx)) require.NoError(t, bc.AddBlock(bc.newBlock(tx))) aer, err := bc.GetAppExecResults(tx.Hash(), trigger.Application) diff --git a/pkg/core/native_oracle_test.go b/pkg/core/native_oracle_test.go index 9e4bd34ce..7f0612044 100644 --- a/pkg/core/native_oracle_test.go +++ b/pkg/core/native_oracle_test.go @@ -104,7 +104,7 @@ func putOracleRequest(t *testing.T, h util.Uint160, bc *Blockchain, tx.ValidUntilBlock = bc.BlockHeight() + 1 tx.NetworkFee = 1_000_000 setSigner(tx, testchain.MultisigScriptHash()) - require.NoError(t, signTx(bc, tx)) + require.NoError(t, testchain.SignTx(bc, tx)) require.NoError(t, bc.AddBlock(bc.newBlock(tx))) return tx.Hash() } diff --git a/pkg/core/native_policy_test.go b/pkg/core/native_policy_test.go index f9a04eb66..496c6b1b5 100644 --- a/pkg/core/native_policy_test.go +++ b/pkg/core/native_policy_test.go @@ -5,6 +5,7 @@ import ( "testing" "github.com/nspcc-dev/neo-go/internal/random" + "github.com/nspcc-dev/neo-go/internal/testchain" "github.com/nspcc-dev/neo-go/pkg/core/block" "github.com/nspcc-dev/neo-go/pkg/core/native" "github.com/nspcc-dev/neo-go/pkg/core/state" @@ -231,7 +232,7 @@ func invokeNativePolicyMethod(chain *Blockchain, method string, args ...interfac validUntil := chain.blockHeight + 1 tx.ValidUntilBlock = validUntil addSigners(tx) - err := signTx(chain, tx) + err := testchain.SignTx(chain, tx) if err != nil { return nil, err } diff --git a/scripts/gendump/main.go b/scripts/gendump/main.go new file mode 100644 index 000000000..1ce76be2c --- /dev/null +++ b/scripts/gendump/main.go @@ -0,0 +1,193 @@ +package main + +import ( + "crypto/rand" + "errors" + "flag" + "fmt" + "os" + "strings" + "time" + + "github.com/nspcc-dev/neo-go/internal/testchain" + "github.com/nspcc-dev/neo-go/pkg/config" + "github.com/nspcc-dev/neo-go/pkg/config/netmode" + "github.com/nspcc-dev/neo-go/pkg/core" + "github.com/nspcc-dev/neo-go/pkg/core/block" + "github.com/nspcc-dev/neo-go/pkg/core/chaindump" + "github.com/nspcc-dev/neo-go/pkg/core/native" + "github.com/nspcc-dev/neo-go/pkg/core/storage" + "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/io" + "github.com/nspcc-dev/neo-go/pkg/smartcontract" + "github.com/nspcc-dev/neo-go/pkg/vm/emit" + "github.com/nspcc-dev/neo-go/pkg/wallet" + "go.uber.org/zap" + "go.uber.org/zap/zapcore" +) + +// Takes 1 minute for 100 tx per block and 5000 blocks. +const ( + defaultBlockCount = 5000 + defaultTxPerBlock = 100 +) + +var ( + outFile = flag.String("out", "", "filename to write dump to") + blockCount = flag.Uint("blocks", defaultBlockCount, "number of blocks to generate") + txPerBlock = flag.Uint("txs", defaultTxPerBlock, "number of blocks to generate") +) + +func main() { + flag.Parse() + + if *outFile == "" { + handleError("", errors.New("output file is not provided")) + } + outStream, err := os.Create(*outFile) // fail early + handleError("can't open output file", err) + defer outStream.Close() + + const contract = ` + package contract + import "github.com/nspcc-dev/neo-go/pkg/interop/storage" + var ctx = storage.GetContext() + func Put(key, value []byte) { + storage.Put(ctx, key, value) + }` + + acc, err := wallet.NewAccount() + handleError("can't create new account", err) + h := acc.Contract.ScriptHash() + + bc, err := newChain() + handleError("can't initialize blockchain", err) + + valScript, err := smartcontract.CreateDefaultMultiSigRedeemScript(bc.GetStandByValidators()) + handleError("can't create verification script", err) + lastBlock, err := bc.GetBlock(bc.GetHeaderHash(int(bc.BlockHeight()))) + handleError("can't fetch last block", err) + + txMoveNeo, err := testchain.NewTransferFromOwner(bc, bc.GoverningTokenHash(), h, native.NEOTotalSupply, 0, 2) + handleError("can't transfer NEO", err) + txMoveGas, err := testchain.NewTransferFromOwner(bc, bc.UtilityTokenHash(), h, 2_000_000_000_000_000, 0, 2) + handleError("can't tranfser GAS", err) + lastBlock = addBlock(bc, lastBlock, valScript, txMoveNeo, txMoveGas) + + tx, avm, err := testchain.NewDeployTx("DumpContract", strings.NewReader(contract)) + handleError("can't create deploy tx", err) + tx.Signers = []transaction.Signer{{ + Account: h, + Scopes: transaction.CalledByEntry, + }} + tx.NetworkFee = 10_000_000 + tx.ValidUntilBlock = bc.BlockHeight() + 1 + handleError("can't sign deploy tx", acc.SignTx(tx)) + lastBlock = addBlock(bc, lastBlock, valScript, tx) + + contractHash := hash.Hash160(avm) + key := make([]byte, 10) + value := make([]byte, 10) + nonce := uint32(0) + + blocksNum := uint32(*blockCount) + txNum := int(*txPerBlock) + for i := bc.BlockHeight(); i < blocksNum; i++ { + txs := make([]*transaction.Transaction, txNum) + for j := 0; j < txNum; j++ { + nonce++ + rand.Read(key) + rand.Read(value) + + w := io.NewBufBinWriter() + emit.AppCallWithOperationAndArgs(w.BinWriter, contractHash, "put", key, value) + handleError("can't create transaction", w.Err) + + tx := transaction.New(netmode.UnitTestNet, w.Bytes(), 4_000_000) + tx.ValidUntilBlock = i + 1 + tx.NetworkFee = 4_000_000 + tx.Nonce = nonce + tx.Signers = []transaction.Signer{{ + Account: h, + Scopes: transaction.CalledByEntry, + }} + handleError("can't sign tx", acc.SignTx(tx)) + + txs[j] = tx + } + lastBlock = addBlock(bc, lastBlock, valScript, txs...) + } + + w := io.NewBinWriterFromIO(outStream) + w.WriteU32LE(bc.BlockHeight() + 1) + handleError("error during dump", chaindump.Dump(bc, w, 0, bc.BlockHeight()+1)) +} + +func handleError(msg string, err error) { + if err != nil { + fmt.Printf("%s: %v\n", msg, err) + os.Exit(1) + } +} + +func newChain() (*core.Blockchain, error) { + unitTestNetCfg, err := config.Load("./config", netmode.UnitTestNet) + if err != nil { + return nil, err + } + unitTestNetCfg.ProtocolConfiguration.VerifyBlocks = false + zapCfg := zap.NewDevelopmentConfig() + zapCfg.Level = zap.NewAtomicLevelAt(zapcore.InfoLevel) + log, err := zapCfg.Build() + if err != nil { + return nil, err + } + chain, err := core.NewBlockchain(storage.NewMemoryStore(), unitTestNetCfg.ProtocolConfiguration, log) + if err != nil { + return nil, err + } + go chain.Run() + return chain, nil +} + +func addBlock(bc *core.Blockchain, lastBlock *block.Block, script []byte, txs ...*transaction.Transaction) *block.Block { + b, err := newBlock(bc, lastBlock, script, txs...) + if err != nil { + handleError("can't create block", err) + } + if err := bc.AddBlock(b); err != nil { + handleError("can't add block", err) + } + return b +} + +func newBlock(bc *core.Blockchain, lastBlock *block.Block, script []byte, txs ...*transaction.Transaction) (*block.Block, error) { + witness := transaction.Witness{VerificationScript: script} + b := &block.Block{ + Base: block.Base{ + Network: netmode.UnitTestNet, + PrevHash: lastBlock.Hash(), + Timestamp: uint64(time.Now().UTC().Unix())*1000 + uint64(lastBlock.Index), + Index: lastBlock.Index + 1, + NextConsensus: witness.ScriptHash(), + Script: witness, + }, + ConsensusData: block.ConsensusData{ + PrimaryIndex: 0, + Nonce: 1111, + }, + Transactions: txs, + } + if bc.GetConfig().StateRootInHeader { + sr, err := bc.GetStateRoot(bc.BlockHeight()) + if err != nil { + return nil, err + } + b.StateRootEnabled = true + b.PrevStateRoot = sr.Root + } + b.RebuildMerkleRoot() + b.Script.InvocationScript = testchain.Sign(b.GetSignedPart()) + return b, nil +}