forked from TrueCloudLab/neoneo-go
Merge pull request #2066 from nspcc-dev/block-nonce
Add `System.Runtime.GetRandom`
This commit is contained in:
commit
05cb6586a6
30 changed files with 249 additions and 35 deletions
BIN
cli/testdata/chain50x2.acc
vendored
BIN
cli/testdata/chain50x2.acc
vendored
Binary file not shown.
1
go.mod
1
go.mod
|
@ -17,6 +17,7 @@ require (
|
||||||
github.com/prometheus/client_golang v1.2.1
|
github.com/prometheus/client_golang v1.2.1
|
||||||
github.com/stretchr/testify v1.6.1
|
github.com/stretchr/testify v1.6.1
|
||||||
github.com/syndtr/goleveldb v0.0.0-20180307113352-169b1b37be73
|
github.com/syndtr/goleveldb v0.0.0-20180307113352-169b1b37be73
|
||||||
|
github.com/twmb/murmur3 v1.1.5
|
||||||
github.com/urfave/cli v1.20.0
|
github.com/urfave/cli v1.20.0
|
||||||
github.com/virtuald/go-ordered-json v0.0.0-20170621173500-b18e6e673d74
|
github.com/virtuald/go-ordered-json v0.0.0-20170621173500-b18e6e673d74
|
||||||
go.etcd.io/bbolt v1.3.4
|
go.etcd.io/bbolt v1.3.4
|
||||||
|
|
2
go.sum
2
go.sum
|
@ -228,6 +228,8 @@ github.com/stretchr/testify v1.6.1 h1:hDPOHmpOpP40lSULcqw7IrRb/u7w6RpDC9399XyoNd
|
||||||
github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
||||||
github.com/syndtr/goleveldb v0.0.0-20180307113352-169b1b37be73 h1:I2drr5K0tykBofr74ZEGliE/Hf6fNkEbcPyFvsy7wZk=
|
github.com/syndtr/goleveldb v0.0.0-20180307113352-169b1b37be73 h1:I2drr5K0tykBofr74ZEGliE/Hf6fNkEbcPyFvsy7wZk=
|
||||||
github.com/syndtr/goleveldb v0.0.0-20180307113352-169b1b37be73/go.mod h1:Z4AUp2Km+PwemOoO/VB5AOx9XSsIItzFjoJlOSiYmn0=
|
github.com/syndtr/goleveldb v0.0.0-20180307113352-169b1b37be73/go.mod h1:Z4AUp2Km+PwemOoO/VB5AOx9XSsIItzFjoJlOSiYmn0=
|
||||||
|
github.com/twmb/murmur3 v1.1.5 h1:i9OLS9fkuLzBXjt6dptlAEyk58fJsSTXbRg3SgVyqgk=
|
||||||
|
github.com/twmb/murmur3 v1.1.5/go.mod h1:Qq/R7NUyOfr65zD+6Q5IHKsJLwP7exErjN6lyyq3OSQ=
|
||||||
github.com/ugorji/go/codec v0.0.0-20181204163529-d75b2dcb6bc8/go.mod h1:VFNgLljTbGfSG7qAOspJ7OScBnGdDN/yBr0sguwnwf0=
|
github.com/ugorji/go/codec v0.0.0-20181204163529-d75b2dcb6bc8/go.mod h1:VFNgLljTbGfSG7qAOspJ7OScBnGdDN/yBr0sguwnwf0=
|
||||||
github.com/urfave/cli v1.20.0 h1:fDqGv3UG/4jbVl/QkFwEdddtEDjh/5Ov6X+0B/3bPaw=
|
github.com/urfave/cli v1.20.0 h1:fDqGv3UG/4jbVl/QkFwEdddtEDjh/5Ov6X+0B/3bPaw=
|
||||||
github.com/urfave/cli v1.20.0/go.mod h1:70zkFmudgCuE/ngEzBv17Jvp/497gISqfk5gWijbERA=
|
github.com/urfave/cli v1.20.0/go.mod h1:70zkFmudgCuE/ngEzBv17Jvp/497gISqfk5gWijbERA=
|
||||||
|
|
|
@ -76,6 +76,7 @@ func TestSyscallExecution(t *testing.T) {
|
||||||
"runtime.GetInvocationCounter": {interopnames.SystemRuntimeGetInvocationCounter, nil, false},
|
"runtime.GetInvocationCounter": {interopnames.SystemRuntimeGetInvocationCounter, nil, false},
|
||||||
"runtime.GetNetwork": {interopnames.SystemRuntimeGetNetwork, nil, false},
|
"runtime.GetNetwork": {interopnames.SystemRuntimeGetNetwork, nil, false},
|
||||||
"runtime.GetNotifications": {interopnames.SystemRuntimeGetNotifications, []string{u160}, false},
|
"runtime.GetNotifications": {interopnames.SystemRuntimeGetNotifications, []string{u160}, false},
|
||||||
|
"runtime.GetRandom": {interopnames.SystemRuntimeGetRandom, nil, false},
|
||||||
"runtime.GetScriptContainer": {interopnames.SystemRuntimeGetScriptContainer, nil, false},
|
"runtime.GetScriptContainer": {interopnames.SystemRuntimeGetScriptContainer, nil, false},
|
||||||
"runtime.GetTime": {interopnames.SystemRuntimeGetTime, nil, false},
|
"runtime.GetTime": {interopnames.SystemRuntimeGetTime, nil, false},
|
||||||
"runtime.GetTrigger": {interopnames.SystemRuntimeGetTrigger, nil, false},
|
"runtime.GetTrigger": {interopnames.SystemRuntimeGetTrigger, nil, false},
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
package consensus
|
package consensus
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"crypto/rand"
|
||||||
|
"encoding/binary"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"sort"
|
"sort"
|
||||||
|
@ -239,9 +241,19 @@ func (s *service) newPrepareRequest() payload.PrepareRequest {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
r.nonce = s.getNonce()
|
||||||
return r
|
return r
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (s *service) getNonce() uint64 {
|
||||||
|
b := make([]byte, 8)
|
||||||
|
_, err := rand.Read(b)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
return binary.LittleEndian.Uint64(b)
|
||||||
|
}
|
||||||
|
|
||||||
func (s *service) Start() {
|
func (s *service) Start() {
|
||||||
if s.started.CAS(false, true) {
|
if s.started.CAS(false, true) {
|
||||||
s.log.Info("starting consensus service")
|
s.log.Info("starting consensus service")
|
||||||
|
@ -649,6 +661,7 @@ func (s *service) newBlockFromContext(ctx *dbft.Context) block.Block {
|
||||||
block := &neoBlock{network: s.ProtocolConfiguration.Magic}
|
block := &neoBlock{network: s.ProtocolConfiguration.Magic}
|
||||||
|
|
||||||
block.Block.Timestamp = ctx.Timestamp / nsInMs
|
block.Block.Timestamp = ctx.Timestamp / nsInMs
|
||||||
|
block.Block.Nonce = ctx.PreparationPayloads[ctx.PrimaryIndex].GetPrepareRequest().Nonce()
|
||||||
block.Block.Index = ctx.BlockIndex
|
block.Block.Index = ctx.BlockIndex
|
||||||
if s.ProtocolConfiguration.StateRootInHeader {
|
if s.ProtocolConfiguration.StateRootInHeader {
|
||||||
sr, err := s.Chain.GetStateModule().GetStateRoot(ctx.BlockIndex - 1)
|
sr, err := s.Chain.GetStateModule().GetStateRoot(ctx.BlockIndex - 1)
|
||||||
|
|
|
@ -12,6 +12,7 @@ type prepareRequest struct {
|
||||||
version uint32
|
version uint32
|
||||||
prevHash util.Uint256
|
prevHash util.Uint256
|
||||||
timestamp uint64
|
timestamp uint64
|
||||||
|
nonce uint64
|
||||||
transactionHashes []util.Uint256
|
transactionHashes []util.Uint256
|
||||||
stateRootEnabled bool
|
stateRootEnabled bool
|
||||||
stateRoot util.Uint256
|
stateRoot util.Uint256
|
||||||
|
@ -24,6 +25,7 @@ func (p *prepareRequest) EncodeBinary(w *io.BinWriter) {
|
||||||
w.WriteU32LE(p.version)
|
w.WriteU32LE(p.version)
|
||||||
w.WriteBytes(p.prevHash[:])
|
w.WriteBytes(p.prevHash[:])
|
||||||
w.WriteU64LE(p.timestamp)
|
w.WriteU64LE(p.timestamp)
|
||||||
|
w.WriteU64LE(p.nonce)
|
||||||
w.WriteArray(p.transactionHashes)
|
w.WriteArray(p.transactionHashes)
|
||||||
if p.stateRootEnabled {
|
if p.stateRootEnabled {
|
||||||
w.WriteBytes(p.stateRoot[:])
|
w.WriteBytes(p.stateRoot[:])
|
||||||
|
@ -35,6 +37,7 @@ func (p *prepareRequest) DecodeBinary(r *io.BinReader) {
|
||||||
p.version = r.ReadU32LE()
|
p.version = r.ReadU32LE()
|
||||||
r.ReadBytes(p.prevHash[:])
|
r.ReadBytes(p.prevHash[:])
|
||||||
p.timestamp = r.ReadU64LE()
|
p.timestamp = r.ReadU64LE()
|
||||||
|
p.nonce = r.ReadU64LE()
|
||||||
r.ReadArray(&p.transactionHashes, block.MaxTransactionsPerBlock)
|
r.ReadArray(&p.transactionHashes, block.MaxTransactionsPerBlock)
|
||||||
if p.stateRootEnabled {
|
if p.stateRootEnabled {
|
||||||
r.ReadBytes(p.stateRoot[:])
|
r.ReadBytes(p.stateRoot[:])
|
||||||
|
@ -68,10 +71,10 @@ func (p *prepareRequest) Timestamp() uint64 { return p.timestamp * nsInMs }
|
||||||
func (p *prepareRequest) SetTimestamp(ts uint64) { p.timestamp = ts / nsInMs }
|
func (p *prepareRequest) SetTimestamp(ts uint64) { p.timestamp = ts / nsInMs }
|
||||||
|
|
||||||
// Nonce implements payload.PrepareRequest interface.
|
// Nonce implements payload.PrepareRequest interface.
|
||||||
func (p *prepareRequest) Nonce() uint64 { return 0 }
|
func (p *prepareRequest) Nonce() uint64 { return p.nonce }
|
||||||
|
|
||||||
// SetNonce implements payload.PrepareRequest interface.
|
// SetNonce implements payload.PrepareRequest interface.
|
||||||
func (p *prepareRequest) SetNonce(nonce uint64) {}
|
func (p *prepareRequest) SetNonce(nonce uint64) { p.nonce = nonce }
|
||||||
|
|
||||||
// TransactionHashes implements payload.PrepareRequest interface.
|
// TransactionHashes implements payload.PrepareRequest interface.
|
||||||
func (p *prepareRequest) TransactionHashes() []util.Uint256 { return p.transactionHashes }
|
func (p *prepareRequest) TransactionHashes() []util.Uint256 { return p.transactionHashes }
|
||||||
|
|
|
@ -105,7 +105,7 @@ func TestHashBlockEqualsHashHeader(t *testing.T) {
|
||||||
|
|
||||||
func TestBinBlockDecodeEncode(t *testing.T) {
|
func TestBinBlockDecodeEncode(t *testing.T) {
|
||||||
// block with two transfer transactions taken from C# privnet
|
// block with two transfer transactions taken from C# privnet
|
||||||
rawblock := "AAAAAAwIVa2D6Yha3tArd5XnwkAf7deJBsdyyvpYb2xMZGBbkOUNHAsfre0rKA/F+Ox05/bQSXmcRZnz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wB8MCHRyYW5zZmVyDBTPduKL0AYsSkeO41VhARMZ88+k0kFifVtSOQHGDEDWn0D7z2ELqpN8ghcM/PtfFwo56/BfEasfHuSKECJMYxvU47r2ZtSihg59lGxSZzHsvxTy6nsyvJ22ycNhINdJDECl61cg937N/HujKsLMu2wJMS7C54bzJ3q22Czqllvw3Yp809USgKDs+W+3QD7rI+SFs0OhIn0gooCUU6f/13WjDEDr9XdeT5CGTO8CL0JigzcTcucs0GBcqHs8fToO6zPuuCfS7Wh6dyxSCijT4A4S+7BUdW3dsO7828ke1fj8oNxmkxMMIQIQOn990BZVhZf3lg0nxRakOU/ZaLnmUVXrSwE+QEBAbgwhAqe8Vf6GhOARl2jRBLoweVvcyGYZ6GSt0mFWcj7Rhc1iDCECs2Ir9AF73+MXxYrtX0x1PyBrfbiWBG+n13S7xL9/jcIMIQPZDAffY+aQzneRLhCrUazJRLZoYCN7YIxPj4MJ5x7mmRRBe85spQ=="
|
||||||
rawblockBytes, _ := base64.StdEncoding.DecodeString(rawblock)
|
rawblockBytes, _ := base64.StdEncoding.DecodeString(rawblock)
|
||||||
|
|
||||||
b := New(false)
|
b := New(false)
|
||||||
|
@ -152,7 +152,7 @@ func TestBlockSizeCalculation(t *testing.T) {
|
||||||
// should be the same.In this test we provide more details then necessary because in case of failure we can easily debug the
|
// should be the same.In this test we provide more details then necessary because in case of failure we can easily debug the
|
||||||
// root cause of the size calculation missmatch.
|
// root cause of the size calculation missmatch.
|
||||||
|
|
||||||
rawBlock := "AAAAAAwIVa2D6Yha3tArd5XnwkAf7deJBsdyyvpYb2xMZGBbkOUNHAsfre0rKA/F+Ox05/bQSXmcRZnzK3M6Z+/TxJUh0MNFeAEAAAEAAAAA3u55wYnzAJiwumouuQs6klimx/8BxgxA4MAnF5HGhcOTBjqdXKZIAKcw019v0cSpZj3l04FmLXxAPIPbL1Em2QOE3qBslr1/C4jdLSSq82o3TBr01RqlZgxA6ejwZmZkcfQsbMLS4beqFmtlKuK5eXYj7C7al2X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p809USgKDs+W+3QD7rI+SFs0OhIn0gooCUU6f/13WjDEDr9XdeT5CGTO8CL0JigzcTcucs0GBcqHs8fToO6zPuuCfS7Wh6dyxSCijT4A4S+7BUdW3dsO7828ke1fj8oNxmkxMMIQIQOn990BZVhZf3lg0nxRakOU/ZaLnmUVXrSwE+QEBAbgwhAqe8Vf6GhOARl2jRBLoweVvcyGYZ6GSt0mFWcj7Rhc1iDCECs2Ir9AF73+MXxYrtX0x1PyBrfbiWBG+n13S7xL9/jcIMIQPZDAffY+aQzneRLhCrUazJRLZoYCN7YIxPj4MJ5x7mmRRBe85spQ=="
|
||||||
rawBlockBytes, _ := base64.StdEncoding.DecodeString(rawBlock)
|
rawBlockBytes, _ := base64.StdEncoding.DecodeString(rawBlock)
|
||||||
|
|
||||||
b := New(false)
|
b := New(false)
|
||||||
|
@ -195,12 +195,12 @@ func TestBlockSizeCalculation(t *testing.T) {
|
||||||
|
|
||||||
assert.Equal(t, "DEDgwCcXkcaFw5MGOp1cpkgApzDTX2/RxKlmPeXTgWYtfEA8g9svUSbZA4TeoGyWvX8LiN0tJKrzajdMGvTVGqVmDEDp6PBmZmRx9CxswtLht6oWa2Uq4rl5diPsLtqXZeZepMlxUSbaCdlFTB7iWQG9yKXWR5hc0sScevvuVwwsUYdlDEDwlhwZrP07E5fEQKttVMYAiL7edd/eW2yoMGZe6Q95g7yXQ69edVHfQb61fBw3DjCpMDZ5lsxp3BgzXglJwMSK", base64.StdEncoding.EncodeToString(b.Script.InvocationScript))
|
assert.Equal(t, "DEDgwCcXkcaFw5MGOp1cpkgApzDTX2/RxKlmPeXTgWYtfEA8g9svUSbZA4TeoGyWvX8LiN0tJKrzajdMGvTVGqVmDEDp6PBmZmRx9CxswtLht6oWa2Uq4rl5diPsLtqXZeZepMlxUSbaCdlFTB7iWQG9yKXWR5hc0sScevvuVwwsUYdlDEDwlhwZrP07E5fEQKttVMYAiL7edd/eW2yoMGZe6Q95g7yXQ69edVHfQb61fBw3DjCpMDZ5lsxp3BgzXglJwMSK", base64.StdEncoding.EncodeToString(b.Script.InvocationScript))
|
||||||
assert.Equal(t, "EwwhAhA6f33QFlWFl/eWDSfFFqQ5T9loueZRVetLAT5AQEBuDCECp7xV/oaE4BGXaNEEujB5W9zIZhnoZK3SYVZyPtGFzWIMIQKzYiv0AXvf4xfFiu1fTHU/IGt9uJYEb6fXdLvEv3+NwgwhA9kMB99j5pDOd5EuEKtRrMlEtmhgI3tgjE+PgwnnHuaZFEF7zmyl", base64.StdEncoding.EncodeToString(b.Script.VerificationScript))
|
assert.Equal(t, "EwwhAhA6f33QFlWFl/eWDSfFFqQ5T9loueZRVetLAT5AQEBuDCECp7xV/oaE4BGXaNEEujB5W9zIZhnoZK3SYVZyPtGFzWIMIQKzYiv0AXvf4xfFiu1fTHU/IGt9uJYEb6fXdLvEv3+NwgwhA9kMB99j5pDOd5EuEKtRrMlEtmhgI3tgjE+PgwnnHuaZFEF7zmyl", base64.StdEncoding.EncodeToString(b.Script.VerificationScript))
|
||||||
assert.Equal(t, "02d7c7801742cd404eb178780c840477f1eef4a771ecc8cc9434640fe8f2bb09", b.Hash().StringLE())
|
assert.Equal(t, "0285238e7b5d3ca50ae8f8636dedb4fa486bc0536016e1f1edfd74442af7412e", b.Hash().StringLE())
|
||||||
|
|
||||||
benc, err := testserdes.EncodeBinary(b)
|
benc, err := testserdes.EncodeBinary(b)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
// test size of the block
|
// test size of the block
|
||||||
assert.Equal(t, 1430, len(benc))
|
assert.Equal(t, 1438, len(benc))
|
||||||
assert.Equal(t, rawBlock, base64.StdEncoding.EncodeToString(benc))
|
assert.Equal(t, rawBlock, base64.StdEncoding.EncodeToString(benc))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -3,6 +3,8 @@ package block
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
|
"fmt"
|
||||||
|
"strconv"
|
||||||
|
|
||||||
"github.com/nspcc-dev/neo-go/pkg/core/transaction"
|
"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/hash"
|
||||||
|
@ -28,6 +30,9 @@ type Header struct {
|
||||||
// The height of the block must be exactly equal to the height of the previous block plus 1.
|
// The height of the block must be exactly equal to the height of the previous block plus 1.
|
||||||
Timestamp uint64
|
Timestamp uint64
|
||||||
|
|
||||||
|
// Nonce is block random number.
|
||||||
|
Nonce uint64
|
||||||
|
|
||||||
// index/height of the block
|
// index/height of the block
|
||||||
Index uint32
|
Index uint32
|
||||||
|
|
||||||
|
@ -57,6 +62,7 @@ type baseAux struct {
|
||||||
PrevHash util.Uint256 `json:"previousblockhash"`
|
PrevHash util.Uint256 `json:"previousblockhash"`
|
||||||
MerkleRoot util.Uint256 `json:"merkleroot"`
|
MerkleRoot util.Uint256 `json:"merkleroot"`
|
||||||
Timestamp uint64 `json:"time"`
|
Timestamp uint64 `json:"time"`
|
||||||
|
Nonce string `json:"nonce"`
|
||||||
Index uint32 `json:"index"`
|
Index uint32 `json:"index"`
|
||||||
NextConsensus string `json:"nextconsensus"`
|
NextConsensus string `json:"nextconsensus"`
|
||||||
PrimaryIndex byte `json:"primary"`
|
PrimaryIndex byte `json:"primary"`
|
||||||
|
@ -112,6 +118,7 @@ func (b *Header) encodeHashableFields(bw *io.BinWriter) {
|
||||||
bw.WriteBytes(b.PrevHash[:])
|
bw.WriteBytes(b.PrevHash[:])
|
||||||
bw.WriteBytes(b.MerkleRoot[:])
|
bw.WriteBytes(b.MerkleRoot[:])
|
||||||
bw.WriteU64LE(b.Timestamp)
|
bw.WriteU64LE(b.Timestamp)
|
||||||
|
bw.WriteU64LE(b.Nonce)
|
||||||
bw.WriteU32LE(b.Index)
|
bw.WriteU32LE(b.Index)
|
||||||
bw.WriteB(b.PrimaryIndex)
|
bw.WriteB(b.PrimaryIndex)
|
||||||
bw.WriteBytes(b.NextConsensus[:])
|
bw.WriteBytes(b.NextConsensus[:])
|
||||||
|
@ -127,6 +134,7 @@ func (b *Header) decodeHashableFields(br *io.BinReader) {
|
||||||
br.ReadBytes(b.PrevHash[:])
|
br.ReadBytes(b.PrevHash[:])
|
||||||
br.ReadBytes(b.MerkleRoot[:])
|
br.ReadBytes(b.MerkleRoot[:])
|
||||||
b.Timestamp = br.ReadU64LE()
|
b.Timestamp = br.ReadU64LE()
|
||||||
|
b.Nonce = br.ReadU64LE()
|
||||||
b.Index = br.ReadU32LE()
|
b.Index = br.ReadU32LE()
|
||||||
b.PrimaryIndex = br.ReadB()
|
b.PrimaryIndex = br.ReadB()
|
||||||
br.ReadBytes(b.NextConsensus[:])
|
br.ReadBytes(b.NextConsensus[:])
|
||||||
|
@ -149,6 +157,7 @@ func (b Header) MarshalJSON() ([]byte, error) {
|
||||||
PrevHash: b.PrevHash,
|
PrevHash: b.PrevHash,
|
||||||
MerkleRoot: b.MerkleRoot,
|
MerkleRoot: b.MerkleRoot,
|
||||||
Timestamp: b.Timestamp,
|
Timestamp: b.Timestamp,
|
||||||
|
Nonce: fmt.Sprintf("%016x", b.Nonce),
|
||||||
Index: b.Index,
|
Index: b.Index,
|
||||||
PrimaryIndex: b.PrimaryIndex,
|
PrimaryIndex: b.PrimaryIndex,
|
||||||
NextConsensus: address.Uint160ToString(b.NextConsensus),
|
NextConsensus: address.Uint160ToString(b.NextConsensus),
|
||||||
|
@ -170,6 +179,13 @@ func (b *Header) UnmarshalJSON(data []byte) error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var nonce uint64
|
||||||
|
if len(aux.Nonce) != 0 {
|
||||||
|
nonce, err = strconv.ParseUint(aux.Nonce, 16, 64)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
nextC, err = address.StringToUint160(aux.NextConsensus)
|
nextC, err = address.StringToUint160(aux.NextConsensus)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
@ -181,6 +197,7 @@ func (b *Header) UnmarshalJSON(data []byte) error {
|
||||||
b.PrevHash = aux.PrevHash
|
b.PrevHash = aux.PrevHash
|
||||||
b.MerkleRoot = aux.MerkleRoot
|
b.MerkleRoot = aux.MerkleRoot
|
||||||
b.Timestamp = aux.Timestamp
|
b.Timestamp = aux.Timestamp
|
||||||
|
b.Nonce = nonce
|
||||||
b.Index = aux.Index
|
b.Index = aux.Index
|
||||||
b.PrimaryIndex = aux.PrimaryIndex
|
b.PrimaryIndex = aux.PrimaryIndex
|
||||||
b.NextConsensus = nextC
|
b.NextConsensus = nextC
|
||||||
|
|
|
@ -1908,6 +1908,7 @@ func (bc *Blockchain) newInteropContext(trigger trigger.Type, d dao.DAO, block *
|
||||||
case block != nil:
|
case block != nil:
|
||||||
ic.Container = block
|
ic.Container = block
|
||||||
}
|
}
|
||||||
|
ic.InitNonceData()
|
||||||
return ic
|
return ic
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
package interop
|
package interop
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"encoding/binary"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"sort"
|
"sort"
|
||||||
|
@ -39,6 +40,7 @@ type Context struct {
|
||||||
Natives []Contract
|
Natives []Contract
|
||||||
Trigger trigger.Type
|
Trigger trigger.Type
|
||||||
Block *block.Block
|
Block *block.Block
|
||||||
|
NonceData [16]byte
|
||||||
Tx *transaction.Transaction
|
Tx *transaction.Transaction
|
||||||
DAO *dao.Cached
|
DAO *dao.Cached
|
||||||
Notifications []state.NotificationEvent
|
Notifications []state.NotificationEvent
|
||||||
|
@ -70,6 +72,18 @@ func NewContext(trigger trigger.Type, bc blockchainer.Blockchainer, d dao.DAO,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// InitNonceData initializes nonce to be used in `GetRandom` calculations.
|
||||||
|
func (ic *Context) InitNonceData() {
|
||||||
|
if tx, ok := ic.Container.(*transaction.Transaction); ok {
|
||||||
|
copy(ic.NonceData[:], tx.Hash().BytesBE())
|
||||||
|
}
|
||||||
|
if ic.Block != nil {
|
||||||
|
nonce := ic.Block.Nonce
|
||||||
|
nonce ^= binary.LittleEndian.Uint64(ic.NonceData[:])
|
||||||
|
binary.LittleEndian.PutUint64(ic.NonceData[:], nonce)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Function binds function name, id with the function itself and price,
|
// Function binds function name, id with the function itself and price,
|
||||||
// it's supposed to be inited once for all interopContexts, so it doesn't use
|
// it's supposed to be inited once for all interopContexts, so it doesn't use
|
||||||
// vm.InteropFuncPrice directly.
|
// vm.InteropFuncPrice directly.
|
||||||
|
|
|
@ -26,6 +26,7 @@ const (
|
||||||
SystemRuntimeGetInvocationCounter = "System.Runtime.GetInvocationCounter"
|
SystemRuntimeGetInvocationCounter = "System.Runtime.GetInvocationCounter"
|
||||||
SystemRuntimeGetNetwork = "System.Runtime.GetNetwork"
|
SystemRuntimeGetNetwork = "System.Runtime.GetNetwork"
|
||||||
SystemRuntimeGetNotifications = "System.Runtime.GetNotifications"
|
SystemRuntimeGetNotifications = "System.Runtime.GetNotifications"
|
||||||
|
SystemRuntimeGetRandom = "System.Runtime.GetRandom"
|
||||||
SystemRuntimeGetScriptContainer = "System.Runtime.GetScriptContainer"
|
SystemRuntimeGetScriptContainer = "System.Runtime.GetScriptContainer"
|
||||||
SystemRuntimeGetTime = "System.Runtime.GetTime"
|
SystemRuntimeGetTime = "System.Runtime.GetTime"
|
||||||
SystemRuntimeGetTrigger = "System.Runtime.GetTrigger"
|
SystemRuntimeGetTrigger = "System.Runtime.GetTrigger"
|
||||||
|
@ -64,6 +65,7 @@ var names = []string{
|
||||||
SystemRuntimeGetInvocationCounter,
|
SystemRuntimeGetInvocationCounter,
|
||||||
SystemRuntimeGetNetwork,
|
SystemRuntimeGetNetwork,
|
||||||
SystemRuntimeGetNotifications,
|
SystemRuntimeGetNotifications,
|
||||||
|
SystemRuntimeGetRandom,
|
||||||
SystemRuntimeGetScriptContainer,
|
SystemRuntimeGetScriptContainer,
|
||||||
SystemRuntimeGetTime,
|
SystemRuntimeGetTime,
|
||||||
SystemRuntimeGetTrigger,
|
SystemRuntimeGetTrigger,
|
||||||
|
|
|
@ -1,13 +1,16 @@
|
||||||
package runtime
|
package runtime
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"encoding/binary"
|
||||||
"errors"
|
"errors"
|
||||||
|
|
||||||
"github.com/nspcc-dev/neo-go/pkg/core/interop"
|
"github.com/nspcc-dev/neo-go/pkg/core/interop"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/core/state"
|
"github.com/nspcc-dev/neo-go/pkg/core/state"
|
||||||
|
"github.com/nspcc-dev/neo-go/pkg/encoding/bigint"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/util"
|
"github.com/nspcc-dev/neo-go/pkg/util"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/vm"
|
"github.com/nspcc-dev/neo-go/pkg/vm"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/vm/stackitem"
|
"github.com/nspcc-dev/neo-go/pkg/vm/stackitem"
|
||||||
|
"github.com/twmb/murmur3"
|
||||||
)
|
)
|
||||||
|
|
||||||
// GasLeft returns remaining amount of GAS.
|
// GasLeft returns remaining amount of GAS.
|
||||||
|
@ -74,3 +77,19 @@ func GetNetwork(ic *interop.Context) error {
|
||||||
ic.VM.Estack().PushVal(uint32(m))
|
ic.VM.Estack().PushVal(uint32(m))
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GetRandom returns pseudo-random number which depends on block nonce and transaction hash.
|
||||||
|
func GetRandom(ic *interop.Context) error {
|
||||||
|
res := murmur128(ic.NonceData[:], ic.Network)
|
||||||
|
ic.VM.Estack().PushVal(bigint.FromBytesUnsigned(res))
|
||||||
|
copy(ic.NonceData[:], res)
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func murmur128(data []byte, seed uint32) []byte {
|
||||||
|
h1, h2 := murmur3.SeedSum128(uint64(seed), uint64(seed), data)
|
||||||
|
result := make([]byte, 16)
|
||||||
|
binary.LittleEndian.PutUint64(result, h1)
|
||||||
|
binary.LittleEndian.PutUint64(result[8:], h2)
|
||||||
|
return result
|
||||||
|
}
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
package runtime
|
package runtime
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"encoding/hex"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/nspcc-dev/neo-go/internal/random"
|
"github.com/nspcc-dev/neo-go/internal/random"
|
||||||
|
@ -114,3 +115,20 @@ func TestRuntimeGetInvocationCounter(t *testing.T) {
|
||||||
checkStack(t, ic.VM, 42)
|
checkStack(t, ic.VM, 42)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Test compatibility with C# implementation.
|
||||||
|
// https://github.com/neo-project/neo/blob/master/tests/neo.UnitTests/Cryptography/UT_Murmur128.cs
|
||||||
|
func TestMurmurCompat(t *testing.T) {
|
||||||
|
res := murmur128([]byte("hello"), 123)
|
||||||
|
require.Equal(t, "0bc59d0ad25fde2982ed65af61227a0e", hex.EncodeToString(res))
|
||||||
|
|
||||||
|
res = murmur128([]byte("world"), 123)
|
||||||
|
require.Equal(t, "3d3810fed480472bd214a14023bb407f", hex.EncodeToString(res))
|
||||||
|
|
||||||
|
res = murmur128([]byte("hello world"), 123)
|
||||||
|
require.Equal(t, "e0a0632d4f51302c55e3b3e48d28795d", hex.EncodeToString(res))
|
||||||
|
|
||||||
|
bs, _ := hex.DecodeString("718f952132679baa9c5c2aa0d329fd2a")
|
||||||
|
res = murmur128(bs, 123)
|
||||||
|
require.Equal(t, "9b4aa747ff0cf4e41b3d96251551c8ae", hex.EncodeToString(res))
|
||||||
|
}
|
||||||
|
|
|
@ -8,6 +8,9 @@ import (
|
||||||
|
|
||||||
"github.com/nspcc-dev/neo-go/internal/random"
|
"github.com/nspcc-dev/neo-go/internal/random"
|
||||||
"github.com/nspcc-dev/neo-go/internal/testchain"
|
"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/block"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/core/dao"
|
"github.com/nspcc-dev/neo-go/pkg/core/dao"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/core/interop"
|
"github.com/nspcc-dev/neo-go/pkg/core/interop"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/core/interop/contract"
|
"github.com/nspcc-dev/neo-go/pkg/core/interop/contract"
|
||||||
|
@ -35,6 +38,79 @@ import (
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// Tests are taken from
|
||||||
|
// https://github.com/neo-project/neo/blob/master/tests/neo.UnitTests/SmartContract/UT_ApplicationEngine.Runtime.cs
|
||||||
|
func TestRuntimeGetRandomCompatibility(t *testing.T) {
|
||||||
|
bc := newTestChain(t)
|
||||||
|
|
||||||
|
b := getSharpTestGenesis(t)
|
||||||
|
tx := getSharpTestTx(util.Uint160{})
|
||||||
|
ic := bc.newInteropContext(trigger.Application, dao.NewCached(bc.dao), b, tx)
|
||||||
|
ic.Network = uint32(netmode.MainNet)
|
||||||
|
|
||||||
|
ic.VM = vm.New()
|
||||||
|
ic.VM.LoadScript([]byte{0x01})
|
||||||
|
|
||||||
|
require.NoError(t, runtime.GetRandom(ic))
|
||||||
|
require.Equal(t, "225932872514876835587448704843370203748", ic.VM.Estack().Pop().BigInt().String())
|
||||||
|
|
||||||
|
require.NoError(t, runtime.GetRandom(ic))
|
||||||
|
require.Equal(t, "190129535548110356450238097068474508661", ic.VM.Estack().Pop().BigInt().String())
|
||||||
|
|
||||||
|
require.NoError(t, runtime.GetRandom(ic))
|
||||||
|
require.Equal(t, "48930406787011198493485648810190184269", ic.VM.Estack().Pop().BigInt().String())
|
||||||
|
|
||||||
|
require.NoError(t, runtime.GetRandom(ic))
|
||||||
|
require.Equal(t, "66199389469641263539889463157823839112", ic.VM.Estack().Pop().BigInt().String())
|
||||||
|
|
||||||
|
require.NoError(t, runtime.GetRandom(ic))
|
||||||
|
require.Equal(t, "217172703763162599519098299724476526911", ic.VM.Estack().Pop().BigInt().String())
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestRuntimeGetRandomDifferentTransactions(t *testing.T) {
|
||||||
|
bc := newTestChain(t)
|
||||||
|
b, _ := bc.GetBlock(bc.GetHeaderHash(0))
|
||||||
|
|
||||||
|
tx1 := transaction.New([]byte{byte(opcode.PUSH1)}, 0)
|
||||||
|
ic1 := bc.newInteropContext(trigger.Application, dao.NewCached(bc.dao), b, tx1)
|
||||||
|
ic1.VM = vm.New()
|
||||||
|
ic1.VM.LoadScript(tx1.Script)
|
||||||
|
|
||||||
|
tx2 := transaction.New([]byte{byte(opcode.PUSH2)}, 0)
|
||||||
|
ic2 := bc.newInteropContext(trigger.Application, dao.NewCached(bc.dao), b, tx2)
|
||||||
|
ic2.VM = vm.New()
|
||||||
|
ic2.VM.LoadScript(tx2.Script)
|
||||||
|
|
||||||
|
require.NoError(t, runtime.GetRandom(ic1))
|
||||||
|
require.NoError(t, runtime.GetRandom(ic2))
|
||||||
|
require.NotEqual(t, ic1.VM.Estack().Pop().BigInt(), ic2.VM.Estack().Pop().BigInt())
|
||||||
|
|
||||||
|
require.NoError(t, runtime.GetRandom(ic1))
|
||||||
|
require.NoError(t, runtime.GetRandom(ic2))
|
||||||
|
require.NotEqual(t, ic1.VM.Estack().Pop().BigInt(), ic2.VM.Estack().Pop().BigInt())
|
||||||
|
}
|
||||||
|
|
||||||
|
func getSharpTestTx(sender util.Uint160) *transaction.Transaction {
|
||||||
|
tx := transaction.New([]byte{byte(opcode.PUSH2)}, 0)
|
||||||
|
tx.Nonce = 0
|
||||||
|
tx.Signers = append(tx.Signers, transaction.Signer{
|
||||||
|
Account: sender,
|
||||||
|
Scopes: transaction.CalledByEntry,
|
||||||
|
})
|
||||||
|
tx.Scripts = append(tx.Scripts, transaction.Witness{})
|
||||||
|
return tx
|
||||||
|
}
|
||||||
|
|
||||||
|
func getSharpTestGenesis(t *testing.T) *block.Block {
|
||||||
|
const configPath = "../../config"
|
||||||
|
|
||||||
|
cfg, err := config.Load(configPath, netmode.MainNet)
|
||||||
|
require.NoError(t, err)
|
||||||
|
b, err := createGenesisBlock(cfg.ProtocolConfiguration)
|
||||||
|
require.NoError(t, err)
|
||||||
|
return b
|
||||||
|
}
|
||||||
|
|
||||||
func TestContractCreateAccount(t *testing.T) {
|
func TestContractCreateAccount(t *testing.T) {
|
||||||
v, ic, _ := createVM(t)
|
v, ic, _ := createVM(t)
|
||||||
t.Run("Good", func(t *testing.T) {
|
t.Run("Good", func(t *testing.T) {
|
||||||
|
|
|
@ -52,6 +52,7 @@ var systemInterops = []interop.Function{
|
||||||
{Name: interopnames.SystemRuntimeGetInvocationCounter, Func: runtime.GetInvocationCounter, Price: 1 << 4},
|
{Name: interopnames.SystemRuntimeGetInvocationCounter, Func: runtime.GetInvocationCounter, Price: 1 << 4},
|
||||||
{Name: interopnames.SystemRuntimeGetNetwork, Func: runtime.GetNetwork, Price: 1 << 3},
|
{Name: interopnames.SystemRuntimeGetNetwork, Func: runtime.GetNetwork, Price: 1 << 3},
|
||||||
{Name: interopnames.SystemRuntimeGetNotifications, Func: runtime.GetNotifications, Price: 1 << 8, ParamCount: 1},
|
{Name: interopnames.SystemRuntimeGetNotifications, Func: runtime.GetNotifications, Price: 1 << 8, ParamCount: 1},
|
||||||
|
{Name: interopnames.SystemRuntimeGetRandom, Func: runtime.GetRandom, Price: 1 << 4},
|
||||||
{Name: interopnames.SystemRuntimeGetScriptContainer, Func: engineGetScriptContainer, Price: 1 << 3},
|
{Name: interopnames.SystemRuntimeGetScriptContainer, Func: engineGetScriptContainer, Price: 1 << 3},
|
||||||
{Name: interopnames.SystemRuntimeGetTime, Func: runtime.GetTime, Price: 1 << 3, RequiredFlags: callflag.ReadStates},
|
{Name: interopnames.SystemRuntimeGetTime, Func: runtime.GetTime, Price: 1 << 3, RequiredFlags: callflag.ReadStates},
|
||||||
{Name: interopnames.SystemRuntimeGetTrigger, Func: runtime.GetTrigger, Price: 1 << 3},
|
{Name: interopnames.SystemRuntimeGetTrigger, Func: runtime.GetTrigger, Price: 1 << 3},
|
||||||
|
|
|
@ -200,6 +200,7 @@ func BlockToStackItem(b *block.Block) stackitem.Item {
|
||||||
stackitem.NewByteArray(b.PrevHash.BytesBE()),
|
stackitem.NewByteArray(b.PrevHash.BytesBE()),
|
||||||
stackitem.NewByteArray(b.MerkleRoot.BytesBE()),
|
stackitem.NewByteArray(b.MerkleRoot.BytesBE()),
|
||||||
stackitem.NewBigInteger(big.NewInt(int64(b.Timestamp))),
|
stackitem.NewBigInteger(big.NewInt(int64(b.Timestamp))),
|
||||||
|
stackitem.NewBigInteger(new(big.Int).SetUint64(b.Nonce)),
|
||||||
stackitem.NewBigInteger(big.NewInt(int64(b.Index))),
|
stackitem.NewBigInteger(big.NewInt(int64(b.Index))),
|
||||||
stackitem.NewByteArray(b.NextConsensus.BytesBE()),
|
stackitem.NewByteArray(b.NextConsensus.BytesBE()),
|
||||||
stackitem.NewBigInteger(big.NewInt(int64(len(b.Transactions)))),
|
stackitem.NewBigInteger(big.NewInt(int64(len(b.Transactions)))),
|
||||||
|
|
|
@ -122,7 +122,7 @@ func TestDesignate_DesignateAsRole(t *testing.T) {
|
||||||
bc := newTestChain(t)
|
bc := newTestChain(t)
|
||||||
|
|
||||||
des := bc.contracts.Designate
|
des := bc.contracts.Designate
|
||||||
tx := transaction.New([]byte{}, 0)
|
tx := transaction.New([]byte{byte(opcode.PUSH1)}, 0)
|
||||||
bl := block.New(bc.config.StateRootInHeader)
|
bl := block.New(bc.config.StateRootInHeader)
|
||||||
bl.Index = bc.BlockHeight() + 1
|
bl.Index = bc.BlockHeight() + 1
|
||||||
ic := bc.newInteropContext(trigger.OnPersist, bc.dao, bl, tx)
|
ic := bc.newInteropContext(trigger.OnPersist, bc.dao, bl, tx)
|
||||||
|
|
|
@ -148,15 +148,16 @@ func TestLedgerGetBlock(t *testing.T) {
|
||||||
|
|
||||||
actual, ok := value.([]stackitem.Item)
|
actual, ok := value.([]stackitem.Item)
|
||||||
require.True(t, ok)
|
require.True(t, ok)
|
||||||
require.Equal(t, 8, len(actual))
|
require.Equal(t, 9, len(actual))
|
||||||
require.Equal(t, b.Hash().BytesBE(), actual[0].Value().([]byte))
|
require.Equal(t, b.Hash().BytesBE(), actual[0].Value().([]byte))
|
||||||
require.Equal(t, int64(b.Version), actual[1].Value().(*big.Int).Int64())
|
require.Equal(t, int64(b.Version), actual[1].Value().(*big.Int).Int64())
|
||||||
require.Equal(t, b.PrevHash.BytesBE(), actual[2].Value().([]byte))
|
require.Equal(t, b.PrevHash.BytesBE(), actual[2].Value().([]byte))
|
||||||
require.Equal(t, b.MerkleRoot.BytesBE(), actual[3].Value().([]byte))
|
require.Equal(t, b.MerkleRoot.BytesBE(), actual[3].Value().([]byte))
|
||||||
require.Equal(t, int64(b.Timestamp), actual[4].Value().(*big.Int).Int64())
|
require.Equal(t, int64(b.Timestamp), actual[4].Value().(*big.Int).Int64())
|
||||||
require.Equal(t, int64(b.Index), actual[5].Value().(*big.Int).Int64())
|
require.Equal(t, int64(b.Nonce), actual[5].Value().(*big.Int).Int64())
|
||||||
require.Equal(t, b.NextConsensus.BytesBE(), actual[6].Value().([]byte))
|
require.Equal(t, int64(b.Index), actual[6].Value().(*big.Int).Int64())
|
||||||
require.Equal(t, int64(len(b.Transactions)), actual[7].Value().(*big.Int).Int64())
|
require.Equal(t, b.NextConsensus.BytesBE(), actual[7].Value().([]byte))
|
||||||
|
require.Equal(t, int64(len(b.Transactions)), actual[8].Value().(*big.Int).Int64())
|
||||||
})
|
})
|
||||||
t.Run("bad hash", func(t *testing.T) {
|
t.Run("bad hash", func(t *testing.T) {
|
||||||
res, err := invokeContractMethod(chain, 100000000, ledger, "getBlock", bhash.BytesLE())
|
res, err := invokeContractMethod(chain, 100000000, ledger, "getBlock", bhash.BytesLE())
|
||||||
|
|
|
@ -205,7 +205,7 @@ func TestNEO_CalculateBonus(t *testing.T) {
|
||||||
bc := newTestChain(t)
|
bc := newTestChain(t)
|
||||||
|
|
||||||
neo := bc.contracts.NEO
|
neo := bc.contracts.NEO
|
||||||
tx := transaction.New([]byte{}, 0)
|
tx := transaction.New([]byte{byte(opcode.PUSH1)}, 0)
|
||||||
ic := bc.newInteropContext(trigger.Application, bc.dao, nil, tx)
|
ic := bc.newInteropContext(trigger.Application, bc.dao, nil, tx)
|
||||||
ic.SpawnVM()
|
ic.SpawnVM()
|
||||||
ic.VM.LoadScript([]byte{byte(opcode.RET)})
|
ic.VM.LoadScript([]byte{byte(opcode.RET)})
|
||||||
|
|
|
@ -147,7 +147,7 @@ func TestOracle_Request(t *testing.T) {
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
pub := priv.PublicKey()
|
pub := priv.PublicKey()
|
||||||
|
|
||||||
tx := transaction.New([]byte{}, 0)
|
tx := transaction.New([]byte{byte(opcode.PUSH1)}, 0)
|
||||||
bl := block.New(bc.config.StateRootInHeader)
|
bl := block.New(bc.config.StateRootInHeader)
|
||||||
bl.Index = bc.BlockHeight() + 1
|
bl.Index = bc.BlockHeight() + 1
|
||||||
setSigner(tx, testchain.CommitteeScriptHash())
|
setSigner(tx, testchain.CommitteeScriptHash())
|
||||||
|
|
|
@ -1,13 +1,14 @@
|
||||||
{
|
{
|
||||||
"raw": "0000000052191c07e42694c3b5cf52cac55f9812ea0dbc1778ced9eca81a4695ac682bfda919f78252fb966091b920c013e6b90da9d3855c1f423b5fff57b0b89ae84c0a2a498268770100000001000004e0a3c55cad72028fb5901748b19a27be21f6540401fd4a010c4019c88570296ce982f9bc6d2cd6b951756b04b440182e39147af3662855f909d392861bba73f4eb0b059f7f1750473bb4c221c11c73c4abf4072a6e89eb491a020c40e18599ea4d48bcb5761bad306b563f22f58c65f0dada00c203e0326bc96743eaee363b3007af4a1fdbba9ce67a23ba384b7df05f963b814b2429c9e41c50ea720c4019afbb0bcfa9f84e0340a64c004c65e23ff0d9f00ba6980183b739eb5ba63c5d61e7801ec5d23dcd2af510ee5c91b75d6b4feccd8f3e51e6f21b06bb3c0b692d0c40e0356d3118ffce07c0911d75ff97ffb4b4f3b776b93209d7691bd3ca0a0c9de2812142ef1cc1b4afe10d15d58d1d65c241a31501e50bacfd4f97962ee36fa3890c40036976717446f9ea3958845e2833c23c2a7b611331b0d50ee97de23dedf7a14e6efc64e257588c44493859cc8dc3da7755cf445c76be4c780fdeb291ba2766a8fdfd00150c2103009b7540e10f2562e5fd8fac9eaec25166a58b26e412348ff5a86927bfac22a20c21030205e9cefaea5a1dfc580af20c8d5aa2468bb0148f1a5e4605fc622c80e604ba0c210214baf0ceea3a66f17e7e1e839ea25fd8bed6cd82e6bb6e68250189065f44ff010c21023e9b32ea89b94d066e649b124fd50e396ee91369e8e2a6ae1b11c170d022256d0c2103408dcd416396f64783ac587ea1e1593c57d9fea880c8a6a1920e92a2594778060c2102a7834be9b32e2981d157cb5bbd3acb42cfd11ea5c3b10224d7a44e98c5910f1b0c2102ba2c70f5996f357a43198705859fae2cfea13e1172962800772b3d588a9d4abd170b41138defaf01004883fd4bb494980000000000983c8500000000007f17000002574d3c03df4a9b2772af08e4b296721009b7a6fd00e0a3c55cad72028fb5901748b19a27be21f6540401005f0b0300e40b54020000000c14f6ed986d8f6478b647ddae2083069ca4cfdb23400c14e0a3c55cad72028fb5901748b19a27be21f6540414c01f0c087472616e736665720c1428b3adab7269f9c2181db3cb741ebf551930e27041627d5b523902420c4001a8eb709edc764591af846e7bfba10a908577ad57365b590593a4f81ea5a86ac046b9e1ac69ed39ec30cb97c2c7ef538f00fc105027758454b2bede94cd3bef290c2102a7834be9b32e2981d157cb5bbd3acb42cfd11ea5c3b10224d7a44e98c5910f1b0b4195440d78fd4a010c40e254613ac2b3bd756d907932b15278e62b094a3eab90eff5aa2c56b598161852775cbd76076ac01fe48afdf897077845c415b3ca7884668e94396719b6db66e30c40a7427e3cd5238e3a5d4ab3b4361a37872af3dd8be336b9f1f19f0bd4972edb879b781d0c45dc684da7b220b8d399bea1948c1fe924daa5edbb8df117894130530c4099a1516792326083e50d99d4a97425b31c429136949688081619084403e0065c6ba576a0a4589d9115e3cf71c843c52e476b62ff4349c73838b2c2cb39f6c43d0c409ec13c315e485503ce8d1c821b0ed41ce3f39e914352973ec8ee1fefd024e106e709610bf9d500f56ec0e72c09e427cd8fd0a68bd9ef3b21176e8afd80aaef710c4022d33dc3217be4bb22144d98552ef35f23b1f10367924b4c6bea71d6c280cf2a2fff15f3c9f235cd5620bf310709aa53d6403e6d2fe6d07f13d83803a2c13a7ffdfd00150c2103009b7540e10f2562e5fd8fac9eaec25166a58b26e412348ff5a86927bfac22a20c21030205e9cefaea5a1dfc580af20c8d5aa2468bb0148f1a5e4605fc622c80e604ba0c210214baf0ceea3a66f17e7e1e839ea25fd8bed6cd82e6bb6e68250189065f44ff010c21023e9b32ea89b94d066e649b124fd50e396ee91369e8e2a6ae1b11c170d022256d0c2103408dcd416396f64783ac587ea1e1593c57d9fea880c8a6a1920e92a2594778060c2102a7834be9b32e2981d157cb5bbd3acb42cfd11ea5c3b10224d7a44e98c5910f1b0c2102ba2c70f5996f357a43198705859fae2cfea13e1172962800772b3d588a9d4abd170b41138defaf",
|
"raw": "0000000052191c07e42694c3b5cf52cac55f9812ea0dbc1778ced9eca81a4695ac682bfda919f78252fb966091b920c013e6b90da9d3855c1f423b5fff57b0b89ae84c0a2a4982687701000563412907856341200001000004e0a3c55cad72028fb5901748b19a27be21f6540401fd4a010c4019c88570296ce982f9bc6d2cd6b951756b04b440182e39147af3662855f909d392861bba73f4eb0b059f7f1750473bb4c221c11c73c4abf4072a6e89eb491a020c40e18599ea4d48bcb5761bad306b563f22f58c65f0dada00c203e0326bc96743eaee363b3007af4a1fdbba9ce67a23ba384b7df05f963b814b2429c9e41c50ea720c4019afbb0bcfa9f84e0340a64c004c65e23ff0d9f00ba6980183b739eb5ba63c5d61e7801ec5d23dcd2af510ee5c91b75d6b4feccd8f3e51e6f21b06bb3c0b692d0c40e0356d3118ffce07c0911d75ff97ffb4b4f3b776b93209d7691bd3ca0a0c9de2812142ef1cc1b4afe10d15d58d1d65c241a31501e50bacfd4f97962ee36fa3890c40036976717446f9ea3958845e2833c23c2a7b611331b0d50ee97de23dedf7a14e6efc64e257588c44493859cc8dc3da7755cf445c76be4c780fdeb291ba2766a8fdfd00150c2103009b7540e10f2562e5fd8fac9eaec25166a58b26e412348ff5a86927bfac22a20c21030205e9cefaea5a1dfc580af20c8d5aa2468bb0148f1a5e4605fc622c80e604ba0c210214baf0ceea3a66f17e7e1e839ea25fd8bed6cd82e6bb6e68250189065f44ff010c21023e9b32ea89b94d066e649b124fd50e396ee91369e8e2a6ae1b11c170d022256d0c2103408dcd416396f64783ac587ea1e1593c57d9fea880c8a6a1920e92a2594778060c2102a7834be9b32e2981d157cb5bbd3acb42cfd11ea5c3b10224d7a44e98c5910f1b0c2102ba2c70f5996f357a43198705859fae2cfea13e1172962800772b3d588a9d4abd170b41138defaf01004883fd4bb494980000000000983c8500000000007f17000002574d3c03df4a9b2772af08e4b296721009b7a6fd00e0a3c55cad72028fb5901748b19a27be21f6540401005f0b0300e40b54020000000c14f6ed986d8f6478b647ddae2083069ca4cfdb23400c14e0a3c55cad72028fb5901748b19a27be21f6540414c01f0c087472616e736665720c1428b3adab7269f9c2181db3cb741ebf551930e27041627d5b523902420c4001a8eb709edc764591af846e7bfba10a908577ad57365b590593a4f81ea5a86ac046b9e1ac69ed39ec30cb97c2c7ef538f00fc105027758454b2bede94cd3bef290c2102a7834be9b32e2981d157cb5bbd3acb42cfd11ea5c3b10224d7a44e98c5910f1b0b4195440d78fd4a010c40e254613ac2b3bd756d907932b15278e62b094a3eab90eff5aa2c56b598161852775cbd76076ac01fe48afdf897077845c415b3ca7884668e94396719b6db66e30c40a7427e3cd5238e3a5d4ab3b4361a37872af3dd8be336b9f1f19f0bd4972edb879b781d0c45dc684da7b220b8d399bea1948c1fe924daa5edbb8df117894130530c4099a1516792326083e50d99d4a97425b31c429136949688081619084403e0065c6ba576a0a4589d9115e3cf71c843c52e476b62ff4349c73838b2c2cb39f6c43d0c409ec13c315e485503ce8d1c821b0ed41ce3f39e914352973ec8ee1fefd024e106e709610bf9d500f56ec0e72c09e427cd8fd0a68bd9ef3b21176e8afd80aaef710c4022d33dc3217be4bb22144d98552ef35f23b1f10367924b4c6bea71d6c280cf2a2fff15f3c9f235cd5620bf310709aa53d6403e6d2fe6d07f13d83803a2c13a7ffdfd00150c2103009b7540e10f2562e5fd8fac9eaec25166a58b26e412348ff5a86927bfac22a20c21030205e9cefaea5a1dfc580af20c8d5aa2468bb0148f1a5e4605fc622c80e604ba0c210214baf0ceea3a66f17e7e1e839ea25fd8bed6cd82e6bb6e68250189065f44ff010c21023e9b32ea89b94d066e649b124fd50e396ee91369e8e2a6ae1b11c170d022256d0c2103408dcd416396f64783ac587ea1e1593c57d9fea880c8a6a1920e92a2594778060c2102a7834be9b32e2981d157cb5bbd3acb42cfd11ea5c3b10224d7a44e98c5910f1b0c2102ba2c70f5996f357a43198705859fae2cfea13e1172962800772b3d588a9d4abd170b41138defaf",
|
||||||
"size" : 1564,
|
"size" : 1564,
|
||||||
"index" : 256,
|
"index" : 256,
|
||||||
"primary" : 4,
|
"primary" : 4,
|
||||||
|
"nonce": "0x1234567890123456",
|
||||||
"time" : 1612366104874,
|
"time" : 1612366104874,
|
||||||
"confirmations" : 10883,
|
"confirmations" : 10883,
|
||||||
"previousblockhash" : "0xfd2b68ac95461aa8ecd9ce7817bc0dea12985fc5ca52cfb5c39426e4071c1952",
|
"previousblockhash" : "0xfd2b68ac95461aa8ecd9ce7817bc0dea12985fc5ca52cfb5c39426e4071c1952",
|
||||||
"nextconsensus" : "NgPkjjLTNcQad99iRYeXRUuowE4gxLAnDL",
|
"nextconsensus" : "NgPkjjLTNcQad99iRYeXRUuowE4gxLAnDL",
|
||||||
"hash" : "0x53b3d970ccb235bef785633817f2a947f63bac1f7fa23103f7d080a53f0361f4",
|
"hash" : "0x79cdba60b0197e3e3e7e8b8e42a56fd3a7c1530561da04a030c8201880b11795",
|
||||||
"witnesses" : [
|
"witnesses" : [
|
||||||
{
|
{
|
||||||
"verification" : "FQwhAwCbdUDhDyVi5f2PrJ6uwlFmpYsm5BI0j/WoaSe/rCKiDCEDAgXpzvrqWh38WAryDI1aokaLsBSPGl5GBfxiLIDmBLoMIQIUuvDO6jpm8X5+HoOeol/YvtbNgua7bmglAYkGX0T/AQwhAj6bMuqJuU0GbmSbEk/VDjlu6RNp6OKmrhsRwXDQIiVtDCEDQI3NQWOW9keDrFh+oeFZPFfZ/qiAyKahkg6SollHeAYMIQKng0vpsy4pgdFXy1u9OstCz9EepcOxAiTXpE6YxZEPGwwhAroscPWZbzV6QxmHBYWfriz+oT4RcpYoAHcrPViKnUq9FwtBE43vrw==",
|
"verification" : "FQwhAwCbdUDhDyVi5f2PrJ6uwlFmpYsm5BI0j/WoaSe/rCKiDCEDAgXpzvrqWh38WAryDI1aokaLsBSPGl5GBfxiLIDmBLoMIQIUuvDO6jpm8X5+HoOeol/YvtbNgua7bmglAYkGX0T/AQwhAj6bMuqJuU0GbmSbEk/VDjlu6RNp6OKmrhsRwXDQIiVtDCEDQI3NQWOW9keDrFh+oeFZPFfZ/qiAyKahkg6SollHeAYMIQKng0vpsy4pgdFXy1u9OstCz9EepcOxAiTXpE6YxZEPGwwhAroscPWZbzV6QxmHBYWfriz+oT4RcpYoAHcrPViKnUq9FwtBE43vrw==",
|
||||||
|
|
|
@ -30,6 +30,7 @@ func createGenesisBlock(cfg config.ProtocolConfiguration) (*block.Block, error)
|
||||||
Version: 0,
|
Version: 0,
|
||||||
PrevHash: util.Uint256{},
|
PrevHash: util.Uint256{},
|
||||||
Timestamp: uint64(time.Date(2016, 7, 15, 15, 8, 21, 0, time.UTC).Unix()) * 1000, // Milliseconds.
|
Timestamp: uint64(time.Date(2016, 7, 15, 15, 8, 21, 0, time.UTC).Unix()) * 1000, // Milliseconds.
|
||||||
|
Nonce: 2083236893,
|
||||||
Index: 0,
|
Index: 0,
|
||||||
NextConsensus: nextConsensus,
|
NextConsensus: nextConsensus,
|
||||||
Script: transaction.Witness{
|
Script: transaction.Witness{
|
||||||
|
|
|
@ -17,7 +17,7 @@ func TestGenesisBlockMainNet(t *testing.T) {
|
||||||
block, err := createGenesisBlock(cfg.ProtocolConfiguration)
|
block, err := createGenesisBlock(cfg.ProtocolConfiguration)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
expect := "c3db4ba50ede4f9e749bd97e1499953ae17e65a415c6bf9e38c01cf92b03d156"
|
expect := "1f4d1defa46faa5e7b9b8d3f79a06bec777d7c26c4aa5f6f5899a291daa87c15"
|
||||||
assert.Equal(t, expect, block.Hash().StringLE())
|
assert.Equal(t, expect, block.Hash().StringLE())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -4,6 +4,8 @@ import (
|
||||||
"encoding/binary"
|
"encoding/binary"
|
||||||
"math/big"
|
"math/big"
|
||||||
"math/bits"
|
"math/bits"
|
||||||
|
|
||||||
|
"github.com/nspcc-dev/neo-go/pkg/util"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
@ -13,6 +15,12 @@ const (
|
||||||
wordSizeBytes = bits.UintSize / 8
|
wordSizeBytes = bits.UintSize / 8
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// FromBytesUnsigned converts data in little-endian format to an unsigned integer.
|
||||||
|
func FromBytesUnsigned(data []byte) *big.Int {
|
||||||
|
bs := util.ArrayReverse(data)
|
||||||
|
return new(big.Int).SetBytes(bs)
|
||||||
|
}
|
||||||
|
|
||||||
// FromBytes converts data in little-endian format to
|
// FromBytes converts data in little-endian format to
|
||||||
// an integer.
|
// an integer.
|
||||||
func FromBytes(data []byte) *big.Int {
|
func FromBytes(data []byte) *big.Int {
|
||||||
|
|
|
@ -122,6 +122,31 @@ func TestBytesToInt(t *testing.T) {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var unsignedCases = []struct {
|
||||||
|
number int64
|
||||||
|
buf []byte
|
||||||
|
}{
|
||||||
|
{0xff00000000, []byte{0x00, 0x00, 0x00, 0x00, 0xff}},
|
||||||
|
{0xfd00000000, []byte{0x00, 0x00, 0x00, 0x00, 0xfd}},
|
||||||
|
{0x8000000000, []byte{0x00, 0x00, 0x00, 0x00, 0x80}},
|
||||||
|
{0xff0200000000, []byte{0x00, 0x00, 0x00, 0x00, 0x02, 0xff}},
|
||||||
|
{0xff0100000000, []byte{0x00, 0x00, 0x00, 0x00, 0x01, 0xff}},
|
||||||
|
{0xff0100000000, []byte{0x00, 0x00, 0x00, 0x00, 0x01, 0xff, 0x00}},
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestBytesToUnsigned(t *testing.T) {
|
||||||
|
for _, tc := range testCases {
|
||||||
|
if tc.number > 0 {
|
||||||
|
num := FromBytesUnsigned(tc.buf)
|
||||||
|
assert.Equal(t, tc.number, num.Int64(), "expected %x, got %x", tc.number, num.Int64())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for _, tc := range unsignedCases {
|
||||||
|
num := FromBytesUnsigned(tc.buf)
|
||||||
|
assert.Equal(t, tc.number, num.Int64(), "expected %x, got %x", tc.number, num.Int64())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func TestEquivalentRepresentations(t *testing.T) {
|
func TestEquivalentRepresentations(t *testing.T) {
|
||||||
for _, tc := range testCases {
|
for _, tc := range testCases {
|
||||||
buf := tc.buf
|
buf := tc.buf
|
||||||
|
|
|
@ -19,6 +19,8 @@ type Block struct {
|
||||||
MerkleRoot interop.Hash256
|
MerkleRoot interop.Hash256
|
||||||
// Timestamp represents millisecond-precision block timestamp.
|
// Timestamp represents millisecond-precision block timestamp.
|
||||||
Timestamp int
|
Timestamp int
|
||||||
|
// Nonce represents block nonce.
|
||||||
|
Nonce int
|
||||||
// Index represents the height of the block.
|
// Index represents the height of the block.
|
||||||
Index int
|
Index int
|
||||||
// NextConsensus represents contract address of the next miner (160 bit BE
|
// NextConsensus represents contract address of the next miner (160 bit BE
|
||||||
|
|
|
@ -96,3 +96,10 @@ func GetInvocationCounter() int {
|
||||||
func Platform() []byte {
|
func Platform() []byte {
|
||||||
return neogointernal.Syscall0("System.Runtime.Platform").([]byte)
|
return neogointernal.Syscall0("System.Runtime.Platform").([]byte)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GetRandom returns pseudo-random number which depends on block nonce and tx hash.
|
||||||
|
// Each invocation will return a different number. This function uses
|
||||||
|
// `System.Runtime.GetRandom` syscall.
|
||||||
|
func GetRandom() int {
|
||||||
|
return neogointernal.Syscall0("System.Runtime.GetRandom").(int)
|
||||||
|
}
|
||||||
|
|
|
@ -48,17 +48,17 @@ type rpcClientTestCase struct {
|
||||||
check func(t *testing.T, c *Client, result interface{})
|
check func(t *testing.T, c *Client, result interface{})
|
||||||
}
|
}
|
||||||
|
|
||||||
const base64B1 = "AAAAAAwIVa2D6Yha3tArd5XnwkAf7deJBsdyyvpYb2xMZGBb/YwjvRiYdH/LL9atXcWbYsXLHqkKEutiil4zsK7lKrFxU6tEeAEAAAEAAAAA3u55wYnzAJiwumouuQs6klimx/8BxgxAUfn6Pu/yxlYcuGzwM7RzacB9z9YG7J77DR/j9NfrNR7leWUd0qTqnqiD1H9Vydj401smVWnTg/XAisjZTFpT+gxAAT3EbjC87Gb5UEe+Pvx3AP31lJeIuQL1gKcm6SfJBMaHon2g1dAah3xrKXrj3nGRypvWTKCVEXXDFzEL3ZndswxA/eGxm/DUde1jWbvi+avLdId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DmyQebS50QXoeKdtPyI/FMAfDAh0cmFuc2ZlcgwU9WPqQLwoPU0OBcSOowWz8qBzQO9BYn1bUjkBxgxAvCJ1oPK0B1o5JUaI6G7u5J+K9MWWNsVmLNeYIFV+D0MhB6TU1Or2R09k10XT1wDih4YFgLbTtKE76PvVWQIyFQxARdKrwTJb5mCSGC6kqAo4QcpHEje/FF6wYzuQSi/AaR7Xo1gpXdVU+me52KxAS4Mkg+h3jHKf32ur6h81NttHvwxAl7ZuQANY8vRhQO7fFOmvtbj60BZOFH6dFMl7Lp9D7zdDXYax3N+8ZvJPWdHQfOVf+1i7ZDGiy8o1TVSCiJgu+pMTDCECEDp/fdAWVYWX95YNJ8UWpDlP2Wi55lFV60sBPkBAQG4MIQKnvFX+hoTgEZdo0QS6MHlb3MhmGehkrdJhVnI+0YXNYgwhArNiK/QBe9/jF8WK7V9MdT8ga324lgRvp9d0u8S/f43CDCED2QwH32PmkM53kS4Qq1GsyUS2aGAje2CMT4+DCece5pkUQZ7Q3Do="
|
||||||
|
|
||||||
const b1Verbose = `{"size":1430,"nextblockhash":"0xe03cb7e00a1e04b75f9acd56f22af5f15877a18f4a1cf69991319c4fba0b2fee","confirmations":10,"hash":"0x81a439175d3bdd8961b6223a9b6f6d234f996824c5cfce6af17e6fc14cd84355","version":0,"previousblockhash":"0x5b60644c6c6f58faca72c70689d7ed1f40c2e795772bd0de5a88e983ad55080c","merkleroot":"0xb12ae5aeb0335e8a62eb120aa91ecbc5629bc55dadd62fcb7f749818bd238cfd","time":1616059782001,"index":1,"nextconsensus":"NgEisvCqr2h8wpRxQb7bVPWUZdbVCY8Uo6","primary":0,"witnesses":[{"invocation":"DEBR+fo+7/LGVhy4bPAztHNpwH3P1gbsnvsNH+P01+s1HuV5ZR3SpOqeqIPUf1XJ2PjTWyZVadOD9cCKyNlMWlP6DEABPcRuMLzsZvlQR74+/HcA/fWUl4i5AvWApybpJ8kExoeifaDV0BqHfGspeuPecZHKm9ZMoJURdcMXMQvdmd2zDED94bGb8NR17WNZu+L5q8t0h3RUfauhPKolJwtuWjnG1FEebS4p/o05uXpw0kudKNy6as5BsxWCu4NvtYho6XQT","verification":"EwwhAhA6f33QFlWFl/eWDSfFFqQ5T9loueZRVetLAT5AQEBuDCECp7xV/oaE4BGXaNEEujB5W9zIZhnoZK3SYVZyPtGFzWIMIQKzYiv0AXvf4xfFiu1fTHU/IGt9uJYEb6fXdLvEv3+NwgwhA9kMB99j5pDOd5EuEKtRrMlEtmhgI3tgjE+PgwnnHuaZFEF7zmyl"}],"tx":[{"hash":"0xf5fbd303799f24ba247529d7544d4276cca54ea79f4b98095f2b0557313c5275","size":488,"version":0,"nonce":2,"sender":"NgEisvCqr2h8wpRxQb7bVPWUZdbVCY8Uo6","sysfee":"11000000","netfee":"4421900","validuntilblock":1200,"attributes":[],"signers":[{"account":"0xffc7a658923a0bb92e6abab09800f389c179eede","scopes":"CalledByEntry"}],"script":"CwIY3fUFDBRVVC1T7Q9VRvrUTW6ZkShnAi/OXgwU3u55wYnzAJiwumouuQs6klimx/8UwB8MCHRyYW5zZmVyDBT1Y+pAvCg9TQ4FxI6jBbPyoHNA70FifVtSOQ==","witnesses":[{"invocation":"DEBMibb/TMzF2Iztec98rvVxXh93R6UBnBztgf7RK3chaY8phIxh+J1f3GAtz3zAuLwiSn1wSans9RPKqgepiauoDEBvHFZj5u3aZ7UkfylMc0wh9ydIuvtlVb3Y/6OOn8HN3RCs7VLLgnaT33Rn1gWByLQBzAldjrJnDfxDSGqfSmjfDECEMpyZHe5lfkSBzlPoP9jC22fDS+7TUt7Bkx6ZZf5aDu09IFrWzPitxkvz4SrAygCdJdzMkBXYZPUatkO828FM","verification":"EwwhAhA6f33QFlWFl/eWDSfFFqQ5T9loueZRVetLAT5AQEBuDCECp7xV/oaE4BGXaNEEujB5W9zIZhnoZK3SYVZyPtGFzWIMIQKzYiv0AXvf4xfFiu1fTHU/IGt9uJYEb6fXdLvEv3+NwgwhA9kMB99j5pDOd5EuEKtRrMlEtmhgI3tgjE+PgwnnHuaZFEF7zmyl"}]},{"hash":"0xfe60f7f4c720a7b0fde52f285ca173a3493bbb15eae9f5c44c1f71b493d5693c","size":492,"version":0,"nonce":3,"sender":"NgEisvCqr2h8wpRxQb7bVPWUZdbVCY8Uo6","sysfee":"11000000","netfee":"4425900","validuntilblock":1200,"attributes":[],"signers":[{"account":"0xffc7a658923a0bb92e6abab09800f389c179eede","scopes":"CalledByEntry"}],"script":"CwMA6HZIFwAAAAwUVVQtU+0PVUb61E1umZEoZwIvzl4MFN7uecGJ8wCYsLpqLrkLOpJYpsf/FMAfDAh0cmFuc2ZlcgwUz3bii9AGLEpHjuNVYQETGfPPpNJBYn1bUjk=","witnesses":[{"invocation":"DEDUTymqNCsQOxQvsHZT67aH3kmvrK85sIdtaJ/q1HHpyk2rLtUUn/kDlPpbk0sshkEP2izllCr6tEiA6WJA5ZGLDEDKzE8svrBWwRMlmba9xVDdkEfsgdrzbCNCjIoauFAf6vKAUX9OZUfoTmgQ7P9uxDC52TrQJYkpysXJfN9eUrkoDECMfTD0i3ZOVrHXG/dPnGy1pKX2V7Z/JgNr6yYPBH7K2eYZGRI2fehawd1LwHsDVPM/vpbcOLGfY0UWn3+PcPdy","verification":"EwwhAhA6f33QFlWFl/eWDSfFFqQ5T9loueZRVetLAT5AQEBuDCECp7xV/oaE4BGXaNEEujB5W9zIZhnoZK3SYVZyPtGFzWIMIQKzYiv0AXvf4xfFiu1fTHU/IGt9uJYEb6fXdLvEv3+NwgwhA9kMB99j5pDOd5EuEKtRrMlEtmhgI3tgjE+PgwnnHuaZFEF7zmyl"}]}]}`
|
const b1Verbose = `{"size":1438,"nextblockhash":"0x34c20650683940a7af1881c2798e83acf9bf98aa226025af6c1d32b5530cc900","confirmations":15,"hash":"0x88c1cbf68695f73fb7b7d185c0037ffebdf032327488ebe65e0533d269e7de9b","version":0,"previousblockhash":"0x0f8fb4e17d2ab9f3097af75ca7fd16064160fb8043db94909e00dd4e257b9dc4","merkleroot":"0x2855f471048a5f0c9c60c10592f8997007aa3e52815d1b8c2c2f57e5e340d5f6","time":1626251469001,"nonce":"0","index":1,"nextconsensus":"NVTiAjNgagDkTr5HTzDmQP9kPwPHN5BgVq","primary":0,"witnesses":[{"invocation":"DEBg0hpK90iZlB4ZSCG7BOr7BsvPXGDax360lvqKeNFuzaGI1RYNH50/dhQLxocy90JdsIOyodd1sOJGEjZIt7ztDEAHc2avJzz6tK+FOQMIZO/FEEikJdLJX0+iZXFcsmDRpB7lo2wWMSQbcoTXNg7leuR0VeDsKJ+YdvCuTG5WbiqWDECa6Yjj+bK4te5KR5jdLF5kLt03csyozZcd/X7NPt89IsX01zpX8ec3e+B2qySJIOhEf3cK0i+5U5wyXiFcRI8x","verification":"EwwhAhA6f33QFlWFl/eWDSfFFqQ5T9loueZRVetLAT5AQEBuDCECp7xV/oaE4BGXaNEEujB5W9zIZhnoZK3SYVZyPtGFzWIMIQKzYiv0AXvf4xfFiu1fTHU/IGt9uJYEb6fXdLvEv3+NwgwhA9kMB99j5pDOd5EuEKtRrMlEtmhgI3tgjE+PgwnnHuaZFEGe0Nw6"}],"tx":[{"hash":"0xf01080c50f3198f5a539c4a06d024f1b8bdc2a360a215fa7e2488f79a56d501a","size":488,"version":0,"nonce":2,"sender":"NVTiAjNgagDkTr5HTzDmQP9kPwPHN5BgVq","sysfee":"11000000","netfee":"4421900","validuntilblock":1200,"attributes":[],"signers":[{"account":"0x3f223f6da778e805d1b9b479906c0e8c1ee8b968","scopes":"CalledByEntry"}],"script":"CwIY3fUFDBTunqIsJ+NL0BSPxBCOCPdOj1BIsgwUaLnoHowObJB5tLnRBeh4p20/Ij8UwB8MCHRyYW5zZmVyDBT1Y+pAvCg9TQ4FxI6jBbPyoHNA70FifVtSOQ==","witnesses":[{"invocation":"DEC8InWg8rQHWjklRojobu7kn4r0xZY2xWYs15ggVX4PQyEHpNTU6vZHT2TXRdPXAOKHhgWAttO0oTvo+9VZAjIVDEBF0qvBMlvmYJIYLqSoCjhBykcSN78UXrBjO5BKL8BpHtejWCld1VT6Z7nYrEBLgySD6HeMcp/fa6vqHzU220e/DECXtm5AA1jy9GFA7t8U6a+1uPrQFk4Ufp0UyXsun0PvN0NdhrHc37xm8k9Z0dB85V/7WLtkMaLLyjVNVIKImC76","verification":"EwwhAhA6f33QFlWFl/eWDSfFFqQ5T9loueZRVetLAT5AQEBuDCECp7xV/oaE4BGXaNEEujB5W9zIZhnoZK3SYVZyPtGFzWIMIQKzYiv0AXvf4xfFiu1fTHU/IGt9uJYEb6fXdLvEv3+NwgwhA9kMB99j5pDOd5EuEKtRrMlEtmhgI3tgjE+PgwnnHuaZFEGe0Nw6"}]},{"hash":"0xced32af656e144f6be5d7172ed37747831456cb3eeaac4ee964d0b479b45d3a8","size":492,"version":0,"nonce":3,"sender":"NVTiAjNgagDkTr5HTzDmQP9kPwPHN5BgVq","sysfee":"11000000","netfee":"4425900","validuntilblock":1200,"attributes":[],"signers":[{"account":"0x3f223f6da778e805d1b9b479906c0e8c1ee8b968","scopes":"CalledByEntry"}],"script":"CwMA6HZIFwAAAAwU7p6iLCfjS9AUj8QQjgj3To9QSLIMFGi56B6MDmyQebS50QXoeKdtPyI/FMAfDAh0cmFuc2ZlcgwUz3bii9AGLEpHjuNVYQETGfPPpNJBYn1bUjk=","witnesses":[{"invocation":"DEDgj/SQT84EbWRZ4ZKhyjJTuLwVPDgVlQO3CGmgacItvni9nziJvTxziZXBG/0Hqkv68ddS1EH94RtWlqLQWRCjDEAWZUeSQ8KskILSvoWPN3836xpg/TYzOGiFVoePv91CFnap4fRFxdbporBgnZ/sUsjFZ74U8f+r0riqtvkdMMyGDEDx5iho79oDVYOCwIDH3K1UeDjAT6Hq9YsD9SCfJSE1rRsAdJPh2StYxdh9Jah1lwGbW0U+Wu6zpbVFf5CS6fFc","verification":"EwwhAhA6f33QFlWFl/eWDSfFFqQ5T9loueZRVetLAT5AQEBuDCECp7xV/oaE4BGXaNEEujB5W9zIZhnoZK3SYVZyPtGFzWIMI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dLF5kLt03csyozZcd/X7NPt89IsX01zpX8ec3e+B2qySJIOhEf3cK0i+5U5wyXiFcRI8xkxMMIQIQOn990BZVhZf3lg0nxRakOU/ZaLnmUVXrSwE+QEBAbgwhAqe8Vf6GhOARl2jRBLoweVvcyGYZ6GSt0mFWcj7Rhc1iDCECs2Ir9AF73+MXxYrtX0x1PyBrfbiWBG+n13S7xL9/jcIMIQPZDAffY+aQzneRLhCrUazJRLZoYCN7YIxPj4MJ5x7mmRRBntDcOg=="
|
||||||
|
|
||||||
const header1Verbose = `{"hash":"0x81a439175d3bdd8961b6223a9b6f6d234f996824c5cfce6af17e6fc14cd84355","size":449,"version":0,"previousblockhash":"0x5b60644c6c6f58faca72c70689d7ed1f40c2e795772bd0de5a88e983ad55080c","merkleroot":"0xb12ae5aeb0335e8a62eb120aa91ecbc5629bc55dadd62fcb7f749818bd238cfd","time":1616059782001,"index":1,"nextconsensus":"NgEisvCqr2h8wpRxQb7bVPWUZdbVCY8Uo6","witnesses":[{"invocation":"DEBR+fo+7/LGVhy4bPAztHNpwH3P1gbsnvsNH+P01+s1HuV5ZR3SpOqeqIPUf1XJ2PjTWyZVadOD9cCKyNlMWlP6DEABPcRuMLzsZvlQR74+/HcA/fWUl4i5AvWApybpJ8kExoeifaDV0BqHfGspeuPecZHKm9ZMoJURdcMXMQvdmd2zDED94bGb8NR17WNZu+L5q8t0h3RUfauhPKolJwtuWjnG1FEebS4p/o05uXpw0kudKNy6as5BsxWCu4NvtYho6XQT","verification":"EwwhAhA6f33QFlWFl/eWDSfFFqQ5T9loueZRVetLAT5AQEBuDCECp7xV/oaE4BGXaNEEujB5W9zIZhnoZK3SYVZyPtGFzWIMIQKzYiv0AXvf4xfFiu1fTHU/IGt9uJYEb6fXdLvEv3+NwgwhA9kMB99j5pDOd5EuEKtRrMlEtmhgI3tgjE+PgwnnHuaZFEF7zmyl"}],"confirmations":10,"nextblockhash":"0xe03cb7e00a1e04b75f9acd56f22af5f15877a18f4a1cf69991319c4fba0b2fee"}`
|
const header1Verbose = `{"hash":"0x88c1cbf68695f73fb7b7d185c0037ffebdf032327488ebe65e0533d269e7de9b","size":457,"version":0,"previousblockhash":"0x0f8fb4e17d2ab9f3097af75ca7fd16064160fb8043db94909e00dd4e257b9dc4","merkleroot":"0x2855f471048a5f0c9c60c10592f8997007aa3e52815d1b8c2c2f57e5e340d5f6","time":1626251469001,"index":1,"nextconsensus":"NVTiAjNgagDkTr5HTzDmQP9kPwPHN5BgVq","witnesses":[{"invocation":"DEBg0hpK90iZlB4ZSCG7BOr7BsvPXGDax360lvqKeNFuzaGI1RYNH50/dhQLxocy90JdsIOyodd1sOJGEjZIt7ztDEAHc2avJzz6tK+FOQMIZO/FEEikJdLJX0+iZXFcsmDRpB7lo2wWMSQbcoTXNg7leuR0VeDsKJ+YdvCuTG5WbiqWDECa6Yjj+bK4te5KR5jdLF5kLt03csyozZcd/X7NPt89IsX01zpX8ec3e+B2qySJIOhEf3cK0i+5U5wyXiFcRI8x","verification":"EwwhAhA6f33QFlWFl/eWDSfFFqQ5T9loueZRVetLAT5AQEBuDCECp7xV/oaE4BGXaNEEujB5W9zIZhnoZK3SYVZyPtGFzWIMIQKzYiv0AXvf4xfFiu1fTHU/IGt9uJYEb6fXdLvEv3+NwgwhA9kMB99j5pDOd5EuEKtRrMlEtmhgI3tgjE+PgwnnHuaZFEGe0Nw6"}],"confirmations":15,"nextblockhash":"0x34c20650683940a7af1881c2798e83acf9bf98aa226025af6c1d32b5530cc900"}`
|
||||||
|
|
||||||
const txMoveNeoVerbose = `{"blockhash":"0x81a439175d3bdd8961b6223a9b6f6d234f996824c5cfce6af17e6fc14cd84355","confirmations":10,"blocktime":1616059782001,"vmstate":"HALT","hash":"0xf5fbd303799f24ba247529d7544d4276cca54ea79f4b98095f2b0557313c5275","size":488,"version":0,"nonce":2,"sender":"NgEisvCqr2h8wpRxQb7bVPWUZdbVCY8Uo6","sysfee":"11000000","netfee":"4421900","validuntilblock":1200,"attributes":[],"signers":[{"account":"0xffc7a658923a0bb92e6abab09800f389c179eede","scopes":"CalledByEntry"}],"script":"CwIY3fUFDBRVVC1T7Q9VRvrUTW6ZkShnAi/OXgwU3u55wYnzAJiwumouuQs6klimx/8UwB8MCHRyYW5zZmVyDBT1Y+pAvCg9TQ4FxI6jBbPyoHNA70FifVtSOQ==","witnesses":[{"invocation":"DEBMibb/TMzF2Iztec98rvVxXh93R6UBnBztgf7RK3chaY8phIxh+J1f3GAtz3zAuLwiSn1wSans9RPKqgepiauoDEBvHFZj5u3aZ7UkfylMc0wh9ydIuvtlVb3Y/6OOn8HN3RCs7VLLgnaT33Rn1gWByLQBzAldjrJnDfxDSGqfSmjfDECEMpyZHe5lfkSBzlPoP9jC22fDS+7TUt7Bkx6ZZf5aDu09IFrWzPitxkvz4SrAygCdJdzMkBXYZPUatkO828FM","verification":"EwwhAhA6f33QFlWFl/eWDSfFFqQ5T9loueZRVetLAT5AQEBuDCECp7xV/oaE4BGXaNEEujB5W9zIZhnoZK3SYVZyPtGFzWIMIQKzYiv0AXvf4xfFiu1fTHU/IGt9uJYEb6fXdLvEv3+NwgwhA9kMB99j5pDOd5EuEKtRrMlEtmhgI3tgjE+PgwnnHuaZFEF7zmyl"}]}`
|
const txMoveNeoVerbose = `{"blockhash":"0x88c1cbf68695f73fb7b7d185c0037ffebdf032327488ebe65e0533d269e7de9b","confirmations":15,"blocktime":1626251469001,"vmstate":"HALT","hash":"0xf01080c50f3198f5a539c4a06d024f1b8bdc2a360a215fa7e2488f79a56d501a","size":488,"version":0,"nonce":2,"sender":"NVTiAjNgagDkTr5HTzDmQP9kPwPHN5BgVq","sysfee":"11000000","netfee":"4421900","validuntilblock":1200,"attributes":[],"signers":[{"account":"0x3f223f6da778e805d1b9b479906c0e8c1ee8b968","scopes":"CalledByEntry"}],"script":"CwIY3fUFDBTunqIsJ+NL0BSPxBCOCPdOj1BIsgwUaLnoHowObJB5tLnRBeh4p20/Ij8UwB8MCHRyYW5zZmVyDBT1Y+pAvCg9TQ4FxI6jBbPyoHNA70FifVtSOQ==","witnesses":[{"invocation":"DEC8InWg8rQHWjklRojobu7kn4r0xZY2xWYs15ggVX4PQyEHpNTU6vZHT2TXRdPXAOKHhgWAttO0oTvo+9VZAjIVDEBF0qvBMlvmYJIYLqSoCjhBykcSN78UXrBjO5BKL8BpHtejWCld1VT6Z7nYrEBLgySD6HeMcp/fa6vqHzU220e/DECXtm5AA1jy9GFA7t8U6a+1uPrQFk4Ufp0UyXsun0PvN0NdhrHc37xm8k9Z0dB85V/7WLtkMaLLyjVNVIKImC76","verification":"EwwhAhA6f33QFlWFl/eWDSfFFqQ5T9loueZRVetLAT5AQEBuDCECp7xV/oaE4BGXaNEEujB5W9zIZhnoZK3SYVZyPtGFzWIMIQKzYiv0AXvf4xfFiu1fTHU/IGt9uJYEb6fXdLvEv3+NwgwhA9kMB99j5pDOd5EuEKtRrMlEtmhgI3tgjE+PgwnnHuaZFEGe0Nw6"}]}`
|
||||||
|
|
||||||
// getResultBlock1 returns data for block number 1 which is used by several tests.
|
// getResultBlock1 returns data for block number 1 which is used by several tests.
|
||||||
func getResultBlock1() *result.Block {
|
func getResultBlock1() *result.Block {
|
||||||
|
@ -71,16 +71,16 @@ func getResultBlock1() *result.Block {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
b2Hash, err := util.Uint256DecodeStringLE("e03cb7e00a1e04b75f9acd56f22af5f15877a18f4a1cf69991319c4fba0b2fee")
|
b2Hash, err := util.Uint256DecodeStringLE("34c20650683940a7af1881c2798e83acf9bf98aa226025af6c1d32b5530cc900")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
return &result.Block{
|
return &result.Block{
|
||||||
Block: *b,
|
Block: *b,
|
||||||
BlockMetadata: result.BlockMetadata{
|
BlockMetadata: result.BlockMetadata{
|
||||||
Size: 1430,
|
Size: 1438,
|
||||||
NextBlockHash: &b2Hash,
|
NextBlockHash: &b2Hash,
|
||||||
Confirmations: 10,
|
Confirmations: 15,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -265,7 +265,7 @@ var rpcClientTestCases = map[string][]rpcClientTestCase{
|
||||||
b := getResultBlock1()
|
b := getResultBlock1()
|
||||||
return &result.Header{
|
return &result.Header{
|
||||||
Hash: b.Hash(),
|
Hash: b.Hash(),
|
||||||
Size: 449,
|
Size: 457,
|
||||||
Version: b.Version,
|
Version: b.Version,
|
||||||
NextBlockHash: b.NextBlockHash,
|
NextBlockHash: b.NextBlockHash,
|
||||||
PrevBlockHash: b.PrevHash,
|
PrevBlockHash: b.PrevHash,
|
||||||
|
|
|
@ -54,15 +54,15 @@ type rpcTestCase struct {
|
||||||
check func(t *testing.T, e *executor, result interface{})
|
check func(t *testing.T, e *executor, result interface{})
|
||||||
}
|
}
|
||||||
|
|
||||||
const testContractHash = "63cc6571e990dd3f345f699fc9c2a6e49edb89af"
|
const testContractHash = "bb6a679438ce0fc6cb0ed1aa85ce83cf96cd3aeb"
|
||||||
const deploymentTxHash = "9b0c586eb07f8c9b6fc46b05c78d87651d50af8e1f44478827848d826f8cd174"
|
const deploymentTxHash = "1f8792e07f223e5e83f86cda3327cbe78c15ea382a1c350101c9119747682ce2"
|
||||||
const genesisBlockHash = "73fe50b5564d57118296cbab0a78fe7cb11c97b7699d07a9a21fab60e79bb8fc"
|
const genesisBlockHash = "0f8fb4e17d2ab9f3097af75ca7fd16064160fb8043db94909e00dd4e257b9dc4"
|
||||||
|
|
||||||
const verifyContractHash = "c50082e0d8364d61ce6933bd24027a3363474dce"
|
const verifyContractHash = "f68822e4ecd93de334bdf1f7c409eda3431bcbd0"
|
||||||
const verifyContractAVM = "VwMAQS1RCDAhcAwU7p6iLCfjS9AUj8QQjgj3To9QSLLbMHFoE87bKGnbKJdA"
|
const verifyContractAVM = "VwIAQS1RCDAhcAwU7p6iLCfjS9AUj8QQjgj3To9QSLLbMHFoE87bKGnbKJdA"
|
||||||
const verifyWithArgsContractHash = "8744ffdd07af8e9f18ab90685c8c2ebfd37c6415"
|
const verifyWithArgsContractHash = "947c780f45b2a3d32e946355ee5cb57faf4decb7"
|
||||||
const invokescriptContractAVM = "VwcADBQBDAMOBQYMDQIODw0DDgcJAAAAANswcGhB+CfsjCGqJgQRQAwUDQ8DAgkAAgEDBwMEBQIBAA4GDAnbMHFpQfgn7IwhqiYEEkATQA=="
|
const invokescriptContractAVM = "VwIADBQBDAMOBQYMDQIODw0DDgcJAAAAANswcGhB+CfsjCGqJgQRQAwUDQ8DAgkAAgEDBwMEBQIBAA4GDAnbMHFpQfgn7IwhqiYEEkATQA=="
|
||||||
const nameServiceContractHash = "60d78a0fc048399438c3764f8a67d0fc86d6e0e6"
|
const nameServiceContractHash = "66206eb850818ec862a9332e0da10b9b7826cb0b"
|
||||||
|
|
||||||
var rpcTestCases = map[string][]rpcTestCase{
|
var rpcTestCases = map[string][]rpcTestCase{
|
||||||
"getapplicationlog": {
|
"getapplicationlog": {
|
||||||
|
@ -1643,7 +1643,7 @@ func checkNep17Balances(t *testing.T, e *executor, acc interface{}) {
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Asset: e.chain.UtilityTokenHash(),
|
Asset: e.chain.UtilityTokenHash(),
|
||||||
Amount: "57941360260",
|
Amount: "57941227260",
|
||||||
LastUpdated: 15,
|
LastUpdated: 15,
|
||||||
}},
|
}},
|
||||||
Address: testchain.PrivateKeyByID(0).GetScriptHash().StringLE(),
|
Address: testchain.PrivateKeyByID(0).GetScriptHash().StringLE(),
|
||||||
|
|
BIN
pkg/rpc/server/testdata/testblocks.acc
vendored
BIN
pkg/rpc/server/testdata/testblocks.acc
vendored
Binary file not shown.
Loading…
Reference in a new issue