diff --git a/internal/basicchain/basic.go b/internal/basicchain/basic.go index 812012aa0a..888143bc81 100644 --- a/internal/basicchain/basic.go +++ b/internal/basicchain/basic.go @@ -8,6 +8,7 @@ import ( "path/filepath" "testing" + "github.com/nspcc-dev/neo-go/pkg/config" "github.com/nspcc-dev/neo-go/pkg/core/native" "github.com/nspcc-dev/neo-go/pkg/core/native/nativenames" "github.com/nspcc-dev/neo-go/pkg/core/native/noderoles" @@ -81,6 +82,11 @@ func Init(t *testing.T, rootpath string, e *neotest.Executor) { t.Fatal("P2PSigExtensions should be enabled to init basic chain") } + const notaryDepositHeight uint32 = 8 + echidnaH, ok := e.Chain.GetConfig().Hardforks[config.HFEchidna.String()] + require.Truef(t, ok, "%s hardfork should be enabled since basic chain uses Notary contract", config.HFEchidna.String()) + require.LessOrEqualf(t, echidnaH, notaryDepositHeight-1, "%s hardfork should be enabled starting from height %d, got: %d", config.HFEchidna.String(), notaryDepositHeight-1, echidnaH) + var ( // examplesPrefix is a prefix of the example smart-contracts. examplesPrefix = filepath.Join(rootpath, "examples") @@ -189,6 +195,7 @@ func Init(t *testing.T, rootpath string, e *neotest.Executor) { // Block #8: deposit some GAS to notary contract for priv0. transferTxH = gasPriv0Invoker.Invoke(t, true, "transfer", priv0ScriptHash, notaryHash, 10_0000_0000, []any{priv0ScriptHash, int64(e.Chain.BlockHeight() + 1000)}) t.Logf("notaryDepositTxPriv0: %v", transferTxH.StringLE()) + require.Equal(t, uint32(notaryDepositHeight), e.Chain.BlockHeight(), "notaryDepositHeight constant is out of date") // Block #9: designate new Notary node. ntr, err := wallet.NewWalletFromFile(path.Join(notaryModulePath, "./testdata/notary1.json")) diff --git a/pkg/core/blockchain_neotest_test.go b/pkg/core/blockchain_neotest_test.go index 892a585282..e6dabb5b41 100644 --- a/pkg/core/blockchain_neotest_test.go +++ b/pkg/core/blockchain_neotest_test.go @@ -2572,7 +2572,7 @@ func TestBlockchain_GenesisTransactionExtension(t *testing.T) { // in the right order. func TestNativenames(t *testing.T) { bc, _ := chain.NewSingleWithCustomConfig(t, func(cfg *config.Blockchain) { - cfg.Hardforks = map[string]uint32{} + cfg.Hardforks = nil // default (all hardforks enabled) behaviour. cfg.P2PSigExtensions = true }) natives := bc.GetNatives() diff --git a/pkg/core/native/native_test/management_test.go b/pkg/core/native/native_test/management_test.go index 9870e81f01..9adc7e5c5b 100644 --- a/pkg/core/native/native_test/management_test.go +++ b/pkg/core/native/native_test/management_test.go @@ -47,7 +47,6 @@ var ( nativenames.Policy: `{"id":-7,"hash":"0xcc5e4edd9f5f8dba8bb65734541df7a1c081c67b","nef":{"magic":860243278,"compiler":"neo-core-v3.0","source":"","tokens":[],"script":"EEEa93tnQBBBGvd7Z0AQQRr3e2dAEEEa93tnQBBBGvd7Z0AQQRr3e2dAEEEa93tnQBBBGvd7Z0AQQRr3e2dAEEEa93tnQBBBGvd7Z0A=","checksum":1094259016},"manifest":{"name":"PolicyContract","abi":{"methods":[{"name":"blockAccount","offset":0,"parameters":[{"name":"account","type":"Hash160"}],"returntype":"Boolean","safe":false},{"name":"getAttributeFee","offset":7,"parameters":[{"name":"attributeType","type":"Integer"}],"returntype":"Integer","safe":true},{"name":"getExecFeeFactor","offset":14,"parameters":[],"returntype":"Integer","safe":true},{"name":"getFeePerByte","offset":21,"parameters":[],"returntype":"Integer","safe":true},{"name":"getStoragePrice","offset":28,"parameters":[],"returntype":"Integer","safe":true},{"name":"isBlocked","offset":35,"parameters":[{"name":"account","type":"Hash160"}],"returntype":"Boolean","safe":true},{"name":"setAttributeFee","offset":42,"parameters":[{"name":"attributeType","type":"Integer"},{"name":"value","type":"Integer"}],"returntype":"Void","safe":false},{"name":"setExecFeeFactor","offset":49,"parameters":[{"name":"value","type":"Integer"}],"returntype":"Void","safe":false},{"name":"setFeePerByte","offset":56,"parameters":[{"name":"value","type":"Integer"}],"returntype":"Void","safe":false},{"name":"setStoragePrice","offset":63,"parameters":[{"name":"value","type":"Integer"}],"returntype":"Void","safe":false},{"name":"unblockAccount","offset":70,"parameters":[{"name":"account","type":"Hash160"}],"returntype":"Boolean","safe":false}],"events":[]},"features":{},"groups":[],"permissions":[{"contract":"*","methods":"*"}],"supportedstandards":[],"trusts":[],"extra":null},"updatecounter":0}`, nativenames.Designation: `{"id":-8,"hash":"0x49cf4e5378ffcd4dec034fd98a174c5491e395e2","nef":{"magic":860243278,"compiler":"neo-core-v3.0","source":"","tokens":[],"script":"EEEa93tnQBBBGvd7Z0A=","checksum":983638438},"manifest":{"name":"RoleManagement","abi":{"methods":[{"name":"designateAsRole","offset":0,"parameters":[{"name":"role","type":"Integer"},{"name":"nodes","type":"Array"}],"returntype":"Void","safe":false},{"name":"getDesignatedByRole","offset":7,"parameters":[{"name":"role","type":"Integer"},{"name":"index","type":"Integer"}],"returntype":"Array","safe":true}],"events":[{"name":"Designation","parameters":[{"name":"Role","type":"Integer"},{"name":"BlockIndex","type":"Integer"}]}]},"features":{},"groups":[],"permissions":[{"contract":"*","methods":"*"}],"supportedstandards":[],"trusts":[],"extra":null},"updatecounter":0}`, nativenames.Oracle: `{"id":-9,"hash":"0xfe924b7cfe89ddd271abaf7210a80a7e11178758","nef":{"magic":860243278,"compiler":"neo-core-v3.0","source":"","tokens":[],"script":"EEEa93tnQBBBGvd7Z0AQQRr3e2dAEEEa93tnQBBBGvd7Z0A=","checksum":2663858513},"manifest":{"name":"OracleContract","abi":{"methods":[{"name":"finish","offset":0,"parameters":[],"returntype":"Void","safe":false},{"name":"getPrice","offset":7,"parameters":[],"returntype":"Integer","safe":true},{"name":"request","offset":14,"parameters":[{"name":"url","type":"String"},{"name":"filter","type":"String"},{"name":"callback","type":"String"},{"name":"userData","type":"Any"},{"name":"gasForResponse","type":"Integer"}],"returntype":"Void","safe":false},{"name":"setPrice","offset":21,"parameters":[{"name":"price","type":"Integer"}],"returntype":"Void","safe":false},{"name":"verify","offset":28,"parameters":[],"returntype":"Boolean","safe":true}],"events":[{"name":"OracleRequest","parameters":[{"name":"Id","type":"Integer"},{"name":"RequestContract","type":"Hash160"},{"name":"Url","type":"String"},{"name":"Filter","type":"String"}]},{"name":"OracleResponse","parameters":[{"name":"Id","type":"Integer"},{"name":"OriginalTx","type":"Hash256"}]}]},"features":{},"groups":[],"permissions":[{"contract":"*","methods":"*"}],"supportedstandards":[],"trusts":[],"extra":null},"updatecounter":0}`, - nativenames.Notary: `{"id":-10,"hash":"0xc1e14f19c3e60d0b9244d06dd7ba9b113135ec3b","nef":{"magic":860243278,"compiler":"neo-core-v3.0","source":"","tokens":[],"script":"EEEa93tnQBBBGvd7Z0AQQRr3e2dAEEEa93tnQBBBGvd7Z0AQQRr3e2dAEEEa93tnQBBBGvd7Z0A=","checksum":1110259869},"manifest":{"name":"Notary","abi":{"methods":[{"name":"balanceOf","offset":0,"parameters":[{"name":"addr","type":"Hash160"}],"returntype":"Integer","safe":true},{"name":"expirationOf","offset":7,"parameters":[{"name":"addr","type":"Hash160"}],"returntype":"Integer","safe":true},{"name":"getMaxNotValidBeforeDelta","offset":14,"parameters":[],"returntype":"Integer","safe":true},{"name":"lockDepositUntil","offset":21,"parameters":[{"name":"address","type":"Hash160"},{"name":"till","type":"Integer"}],"returntype":"Boolean","safe":false},{"name":"onNEP17Payment","offset":28,"parameters":[{"name":"from","type":"Hash160"},{"name":"amount","type":"Integer"},{"name":"data","type":"Any"}],"returntype":"Void","safe":false},{"name":"setMaxNotValidBeforeDelta","offset":35,"parameters":[{"name":"value","type":"Integer"}],"returntype":"Void","safe":false},{"name":"verify","offset":42,"parameters":[{"name":"signature","type":"Signature"}],"returntype":"Boolean","safe":true},{"name":"withdraw","offset":49,"parameters":[{"name":"from","type":"Hash160"},{"name":"to","type":"Hash160"}],"returntype":"Boolean","safe":false}],"events":[]},"features":{},"groups":[],"permissions":[{"contract":"*","methods":"*"}],"supportedstandards":[],"trusts":[],"extra":null},"updatecounter":0}`, } // cockatriceCSS holds serialized native contract states built for genesis block (with UpdateCounter 0) // under assumption that hardforks from Aspidochelone to Cockatrice (included) are enabled. @@ -55,6 +54,11 @@ var ( nativenames.CryptoLib: `{"id":-3,"hash":"0x726cb6e0cd8628a1350a611384688911ab75f51b","nef":{"magic":860243278,"compiler":"neo-core-v3.0","source":"","tokens":[],"script":"EEEa93tnQBBBGvd7Z0AQQRr3e2dAEEEa93tnQBBBGvd7Z0AQQRr3e2dAEEEa93tnQBBBGvd7Z0AQQRr3e2dAEEEa93tnQBBBGvd7Z0A=","checksum":1094259016},"manifest":{"name":"CryptoLib","abi":{"methods":[{"name":"bls12381Add","offset":0,"parameters":[{"name":"x","type":"InteropInterface"},{"name":"y","type":"InteropInterface"}],"returntype":"InteropInterface","safe":true},{"name":"bls12381Deserialize","offset":7,"parameters":[{"name":"data","type":"ByteArray"}],"returntype":"InteropInterface","safe":true},{"name":"bls12381Equal","offset":14,"parameters":[{"name":"x","type":"InteropInterface"},{"name":"y","type":"InteropInterface"}],"returntype":"Boolean","safe":true},{"name":"bls12381Mul","offset":21,"parameters":[{"name":"x","type":"InteropInterface"},{"name":"mul","type":"ByteArray"},{"name":"neg","type":"Boolean"}],"returntype":"InteropInterface","safe":true},{"name":"bls12381Pairing","offset":28,"parameters":[{"name":"g1","type":"InteropInterface"},{"name":"g2","type":"InteropInterface"}],"returntype":"InteropInterface","safe":true},{"name":"bls12381Serialize","offset":35,"parameters":[{"name":"g","type":"InteropInterface"}],"returntype":"ByteArray","safe":true},{"name":"keccak256","offset":42,"parameters":[{"name":"data","type":"ByteArray"}],"returntype":"ByteArray","safe":true},{"name":"murmur32","offset":49,"parameters":[{"name":"data","type":"ByteArray"},{"name":"seed","type":"Integer"}],"returntype":"ByteArray","safe":true},{"name":"ripemd160","offset":56,"parameters":[{"name":"data","type":"ByteArray"}],"returntype":"ByteArray","safe":true},{"name":"sha256","offset":63,"parameters":[{"name":"data","type":"ByteArray"}],"returntype":"ByteArray","safe":true},{"name":"verifyWithECDsa","offset":70,"parameters":[{"name":"message","type":"ByteArray"},{"name":"pubkey","type":"ByteArray"},{"name":"signature","type":"ByteArray"},{"name":"curveHash","type":"Integer"}],"returntype":"Boolean","safe":true}],"events":[]},"features":{},"groups":[],"permissions":[{"contract":"*","methods":"*"}],"supportedstandards":[],"trusts":[],"extra":null},"updatecounter":0}`, nativenames.Neo: `{"id":-5,"hash":"0xef4073a0f2b305a38ec4050e4d3d28bc40ea63f5","nef":{"magic":860243278,"compiler":"neo-core-v3.0","source":"","tokens":[],"script":"EEEa93tnQBBBGvd7Z0AQQRr3e2dAEEEa93tnQBBBGvd7Z0AQQRr3e2dAEEEa93tnQBBBGvd7Z0AQQRr3e2dAEEEa93tnQBBBGvd7Z0AQQRr3e2dAEEEa93tnQBBBGvd7Z0AQQRr3e2dAEEEa93tnQBBBGvd7Z0AQQRr3e2dAEEEa93tnQBBBGvd7Z0A=","checksum":1325686241},"manifest":{"name":"NeoToken","abi":{"methods":[{"name":"balanceOf","offset":0,"parameters":[{"name":"account","type":"Hash160"}],"returntype":"Integer","safe":true},{"name":"decimals","offset":7,"parameters":[],"returntype":"Integer","safe":true},{"name":"getAccountState","offset":14,"parameters":[{"name":"account","type":"Hash160"}],"returntype":"Array","safe":true},{"name":"getAllCandidates","offset":21,"parameters":[],"returntype":"InteropInterface","safe":true},{"name":"getCandidateVote","offset":28,"parameters":[{"name":"pubKey","type":"PublicKey"}],"returntype":"Integer","safe":true},{"name":"getCandidates","offset":35,"parameters":[],"returntype":"Array","safe":true},{"name":"getCommittee","offset":42,"parameters":[],"returntype":"Array","safe":true},{"name":"getCommitteeAddress","offset":49,"parameters":[],"returntype":"Hash160","safe":true},{"name":"getGasPerBlock","offset":56,"parameters":[],"returntype":"Integer","safe":true},{"name":"getNextBlockValidators","offset":63,"parameters":[],"returntype":"Array","safe":true},{"name":"getRegisterPrice","offset":70,"parameters":[],"returntype":"Integer","safe":true},{"name":"registerCandidate","offset":77,"parameters":[{"name":"pubkey","type":"PublicKey"}],"returntype":"Boolean","safe":false},{"name":"setGasPerBlock","offset":84,"parameters":[{"name":"gasPerBlock","type":"Integer"}],"returntype":"Void","safe":false},{"name":"setRegisterPrice","offset":91,"parameters":[{"name":"registerPrice","type":"Integer"}],"returntype":"Void","safe":false},{"name":"symbol","offset":98,"parameters":[],"returntype":"String","safe":true},{"name":"totalSupply","offset":105,"parameters":[],"returntype":"Integer","safe":true},{"name":"transfer","offset":112,"parameters":[{"name":"from","type":"Hash160"},{"name":"to","type":"Hash160"},{"name":"amount","type":"Integer"},{"name":"data","type":"Any"}],"returntype":"Boolean","safe":false},{"name":"unclaimedGas","offset":119,"parameters":[{"name":"account","type":"Hash160"},{"name":"end","type":"Integer"}],"returntype":"Integer","safe":true},{"name":"unregisterCandidate","offset":126,"parameters":[{"name":"pubkey","type":"PublicKey"}],"returntype":"Boolean","safe":false},{"name":"vote","offset":133,"parameters":[{"name":"account","type":"Hash160"},{"name":"voteTo","type":"PublicKey"}],"returntype":"Boolean","safe":false}],"events":[{"name":"Transfer","parameters":[{"name":"from","type":"Hash160"},{"name":"to","type":"Hash160"},{"name":"amount","type":"Integer"}]},{"name":"CandidateStateChanged","parameters":[{"name":"pubkey","type":"PublicKey"},{"name":"registered","type":"Boolean"},{"name":"votes","type":"Integer"}]},{"name":"Vote","parameters":[{"name":"account","type":"Hash160"},{"name":"from","type":"PublicKey"},{"name":"to","type":"PublicKey"},{"name":"amount","type":"Integer"}]},{"name":"CommitteeChanged","parameters":[{"name":"old","type":"Array"},{"name":"new","type":"Array"}]}]},"features":{},"groups":[],"permissions":[{"contract":"*","methods":"*"}],"supportedstandards":["NEP-17"],"trusts":[],"extra":null},"updatecounter":0}`, } + // echidnaCSS holds serialized native contract states built for genesis block (with UpdateCounter 0) + // under assumption that hardforks from Aspidochelone to Echidna (included) are enabled. + echidnaCSS = map[string]string{ + nativenames.Notary: `{"id":-10,"hash":"0xc1e14f19c3e60d0b9244d06dd7ba9b113135ec3b","nef":{"magic":860243278,"compiler":"neo-core-v3.0","source":"","tokens":[],"script":"EEEa93tnQBBBGvd7Z0AQQRr3e2dAEEEa93tnQBBBGvd7Z0AQQRr3e2dAEEEa93tnQBBBGvd7Z0A=","checksum":1110259869},"manifest":{"name":"Notary","abi":{"methods":[{"name":"balanceOf","offset":0,"parameters":[{"name":"addr","type":"Hash160"}],"returntype":"Integer","safe":true},{"name":"expirationOf","offset":7,"parameters":[{"name":"addr","type":"Hash160"}],"returntype":"Integer","safe":true},{"name":"getMaxNotValidBeforeDelta","offset":14,"parameters":[],"returntype":"Integer","safe":true},{"name":"lockDepositUntil","offset":21,"parameters":[{"name":"address","type":"Hash160"},{"name":"till","type":"Integer"}],"returntype":"Boolean","safe":false},{"name":"onNEP17Payment","offset":28,"parameters":[{"name":"from","type":"Hash160"},{"name":"amount","type":"Integer"},{"name":"data","type":"Any"}],"returntype":"Void","safe":false},{"name":"setMaxNotValidBeforeDelta","offset":35,"parameters":[{"name":"value","type":"Integer"}],"returntype":"Void","safe":false},{"name":"verify","offset":42,"parameters":[{"name":"signature","type":"Signature"}],"returntype":"Boolean","safe":true},{"name":"withdraw","offset":49,"parameters":[{"name":"from","type":"Hash160"},{"name":"to","type":"Hash160"}],"returntype":"Boolean","safe":false}],"events":[]},"features":{},"groups":[],"permissions":[{"contract":"*","methods":"*"}],"supportedstandards":[],"trusts":[],"extra":null},"updatecounter":0}`, + } ) func init() { @@ -63,6 +67,11 @@ func init() { cockatriceCSS[k] = v } } + for k, v := range cockatriceCSS { + if _, ok := echidnaCSS[k]; !ok { + echidnaCSS[k] = v + } + } } func newManagementClient(t *testing.T) *neotest.ContractInvoker { @@ -91,6 +100,10 @@ func TestManagement_GenesisNativeState(t *testing.T) { h := state.CreateNativeContractHash(name) c.InvokeAndCheck(t, func(t testing.TB, stack []stackitem.Item) { si := stack[0] + if _, ok := expected[name]; !ok { + require.Equal(t, stackitem.Null{}, si, fmt.Errorf("contract %s state found", name)) + return + } var cs = &state.Contract{} require.NoError(t, cs.FromStackItem(si), name) jBytes, err := ojson.Marshal(cs) @@ -113,6 +126,7 @@ func TestManagement_GenesisNativeState(t *testing.T) { config.HFAspidochelone.String(): 100500, config.HFBasilisk.String(): 100500, config.HFCockatrice.String(): 100500, + config.HFEchidna.String(): 100500, } cfg.P2PSigExtensions = true }) @@ -148,15 +162,31 @@ func TestManagement_GenesisNativeState(t *testing.T) { }) check(t, mgmt, cockatriceCSS) }) + t.Run("Echidna enabled", func(t *testing.T) { + mgmt := newCustomManagementClient(t, func(cfg *config.Blockchain) { + cfg.Hardforks = map[string]uint32{ + config.HFAspidochelone.String(): 0, + config.HFBasilisk.String(): 0, + config.HFCockatrice.String(): 0, + config.HFEchidna.String(): 0, + } + cfg.P2PSigExtensions = true + }) + check(t, mgmt, echidnaCSS) + }) } func TestManagement_NativeDeployUpdateNotifications(t *testing.T) { - const cockatriceHeight = 3 + const ( + cockatriceHeight = 3 + echidnaHeight = 5 + ) mgmt := newCustomManagementClient(t, func(cfg *config.Blockchain) { cfg.Hardforks = map[string]uint32{ config.HFAspidochelone.String(): 0, config.HFBasilisk.String(): 0, config.HFCockatrice.String(): cockatriceHeight, + config.HFEchidna.String(): echidnaHeight, } cfg.P2PSigExtensions = true }) @@ -169,6 +199,8 @@ func TestManagement_NativeDeployUpdateNotifications(t *testing.T) { var expected []state.NotificationEvent for _, name := range nativenames.All { switch name { + case nativenames.Notary: + continue case nativenames.Gas: expected = append(expected, state.NotificationEvent{ ScriptHash: nativehashes.GasToken, @@ -200,7 +232,7 @@ func TestManagement_NativeDeployUpdateNotifications(t *testing.T) { } require.Equal(t, expected, aer[0].Events) - // Generate some blocks and check Update notifications. + // Generate some blocks and check Update notifications for Cockatrice hardfork. cockatriceBlock := mgmt.GenerateNewBlocks(t, cockatriceHeight)[cockatriceHeight-1] aer, err = mgmt.Chain.GetAppExecResults(cockatriceBlock.Hash(), trigger.OnPersist) require.NoError(t, err) @@ -216,15 +248,35 @@ func TestManagement_NativeDeployUpdateNotifications(t *testing.T) { }) } require.Equal(t, expected, aer[0].Events) + + // Generate some blocks and check Deploy notifications for Echidna hardfork. + mgmt.GenerateNewBlocks(t, echidnaHeight-int(mgmt.Chain.BlockHeight())) + aer, err = mgmt.Chain.GetAppExecResults(mgmt.Chain.GetHeaderHash(mgmt.Chain.BlockHeight()), trigger.OnPersist) + require.NoError(t, err) + require.Equal(t, 1, len(aer)) + expected = expected[:0] + expected = append(expected, state.NotificationEvent{ + ScriptHash: nativehashes.ContractManagement, + Name: "Deploy", + Item: stackitem.NewArray([]stackitem.Item{ + stackitem.Make(nativehashes.Notary), + }), + }) + require.Equal(t, expected, aer[0].Events) } func TestManagement_NativeUpdate(t *testing.T) { - const cockatriceHeight = 3 + const ( + cockatriceHeight = 3 + echidnaHeight = 6 + ) + c := newCustomManagementClient(t, func(cfg *config.Blockchain) { cfg.Hardforks = map[string]uint32{ config.HFAspidochelone.String(): 0, config.HFBasilisk.String(): 0, config.HFCockatrice.String(): cockatriceHeight, + config.HFEchidna.String(): echidnaHeight, } cfg.P2PSigExtensions = true }) @@ -235,7 +287,12 @@ func TestManagement_NativeUpdate(t *testing.T) { for _, name := range nativenames.All { h := state.CreateNativeContractHash(name) cs := c.Chain.GetContractState(h) - require.NotNil(t, cs, name) + if name == nativenames.Notary { + require.Nil(t, cs, name) + continue + } else { + require.NotNil(t, cs, name) + } jBytes, err := ojson.Marshal(cs) require.NoError(t, err, name) require.Equal(t, defaultCSS[name], string(jBytes), fmt.Errorf("contract %s state mismatch", name)) @@ -247,16 +304,50 @@ func TestManagement_NativeUpdate(t *testing.T) { for _, name := range nativenames.All { h := state.CreateNativeContractHash(name) cs := c.Chain.GetContractState(h) - require.NotNil(t, cs, name) + if name == nativenames.Notary { + require.Nil(t, cs, name) + continue + } else { + require.NotNil(t, cs, name) + } + var actual = cs if name == nativenames.Neo || name == nativenames.CryptoLib { // A tiny hack to reuse cockatriceCSS map in the check below. require.Equal(t, uint16(1), cs.UpdateCounter, name) - cs.UpdateCounter-- + cp := *cs + actual = &cp // avoid Management cache corruption. + actual.UpdateCounter-- } - jBytes, err := ojson.Marshal(cs) + jBytes, err := ojson.Marshal(actual) require.NoError(t, err, name) require.Equal(t, cockatriceCSS[name], string(jBytes), fmt.Errorf("contract %s state mismatch", name)) } + + // Add some blocks up to the Echidna enabling height and check the natives state. + for i := c.Chain.BlockHeight(); i < echidnaHeight-1; i++ { + c.AddNewBlock(t) + for _, name := range nativenames.All { + h := state.CreateNativeContractHash(name) + cs := c.Chain.GetContractState(h) + if name == nativenames.Notary { + require.Nil(t, cs, name) + continue + } else { + require.NotNil(t, cs, name) + } + var actual = cs + if name == nativenames.Neo || name == nativenames.CryptoLib { + // A tiny hack to reuse echidnaCSS map in the check below. + require.Equal(t, uint16(1), cs.UpdateCounter, name) + cp := *cs + actual = &cp // avoid Management cache corruption. + actual.UpdateCounter-- + } + jBytes, err := ojson.Marshal(actual) + require.NoError(t, err, name) + require.Equal(t, echidnaCSS[name], string(jBytes), fmt.Errorf("contract %s state mismatch", name)) + } + } } func TestManagement_NativeUpdate_Call(t *testing.T) { @@ -292,12 +383,18 @@ func TestManagement_NativeUpdate_Call(t *testing.T) { // different block heights depending on hardfork settings. This test is located here since it // depends on defaultCSS and cockatriceCSS. func TestBlockchain_GetNatives(t *testing.T) { - const cockatriceHeight = 3 + const ( + cockatriceHeight = 3 + domovoiHeight = 5 + echidnaHeight = 6 + ) bc, acc := chain.NewSingleWithCustomConfig(t, func(cfg *config.Blockchain) { cfg.Hardforks = map[string]uint32{ config.HFAspidochelone.String(): 0, config.HFBasilisk.String(): 0, config.HFCockatrice.String(): cockatriceHeight, + config.HFDomovoi.String(): domovoiHeight, + config.HFEchidna.String(): echidnaHeight, } cfg.P2PSigExtensions = true }) @@ -305,7 +402,7 @@ func TestBlockchain_GetNatives(t *testing.T) { // Check genesis-based native contract states. natives := bc.GetNatives() - require.Equal(t, len(nativenames.All), len(natives)) + require.Equal(t, len(nativenames.All)-1, len(natives)) // Notary is deployed starting from D hardfork. for _, cs := range natives { csFull := state.Contract{ ContractBase: cs.ContractBase, @@ -316,10 +413,10 @@ func TestBlockchain_GetNatives(t *testing.T) { require.Equal(t, defaultCSS[cs.Manifest.Name], string(jBytes), fmt.Errorf("contract %s state mismatch", cs.Manifest.Name)) } - // Check native state after update. + // Check native state after Cockatrice. e.GenerateNewBlocks(t, cockatriceHeight) natives = bc.GetNatives() - require.Equal(t, len(nativenames.All), len(natives)) + require.Equal(t, len(nativenames.All)-1, len(natives)) // Notary is deployed starting from D hardfork. for _, cs := range natives { csFull := state.Contract{ ContractBase: cs.ContractBase, @@ -329,6 +426,20 @@ func TestBlockchain_GetNatives(t *testing.T) { require.NoError(t, err, cs.Manifest.Name) require.Equal(t, cockatriceCSS[cs.Manifest.Name], string(jBytes), fmt.Errorf("contract %s state mismatch", cs.Manifest.Name)) } + + // Check native state after Echidna. + e.GenerateNewBlocks(t, echidnaHeight-cockatriceHeight) + natives = bc.GetNatives() + require.Equal(t, len(nativenames.All), len(natives)) + for _, cs := range natives { + csFull := state.Contract{ + ContractBase: cs.ContractBase, + UpdateCounter: 0, // Since we're comparing only state.NativeContract part, set the update counter to 0 to match the echidnaCSS. + } + jBytes, err := ojson.Marshal(csFull) + require.NoError(t, err, cs.Manifest.Name) + require.Equal(t, echidnaCSS[cs.Manifest.Name], string(jBytes), fmt.Errorf("contract %s state mismatch", cs.Manifest.Name)) + } } func TestManagement_ContractCache(t *testing.T) { diff --git a/pkg/core/native/notary.go b/pkg/core/native/notary.go index fa3cab4361..95a78efce0 100644 --- a/pkg/core/native/notary.go +++ b/pkg/core/native/notary.go @@ -52,7 +52,10 @@ const ( defaultMaxNotValidBeforeDelta = 140 // 20 rounds for 7 validators, a little more than half an hour ) -var maxNotValidBeforeDeltaKey = []byte{10} +var ( + maxNotValidBeforeDeltaKey = []byte{10} + activeIn = config.HFEchidna +) var ( _ interop.Contract = (*Notary)(nil) @@ -200,7 +203,7 @@ func (n *Notary) PostPersist(ic *interop.Context) error { // ActiveIn implements the Contract interface. func (n *Notary) ActiveIn() *config.Hardfork { - return nil + return &activeIn } // onPayment records the deposited amount as belonging to "from" address with a lock diff --git a/pkg/services/rpcsrv/client_test.go b/pkg/services/rpcsrv/client_test.go index 98e874567f..f4e2deebf7 100644 --- a/pkg/services/rpcsrv/client_test.go +++ b/pkg/services/rpcsrv/client_test.go @@ -465,6 +465,10 @@ func TestClientNEOContract(t *testing.T) { func TestClientNotary(t *testing.T) { chain, _, httpSrv := initServerWithInMemoryChain(t) + // Echidna should be enabled since this test uses Notary contract. + _, ok := chain.GetConfig().Hardforks[config.HFEchidna.String()] + require.True(t, ok) + c, err := rpcclient.New(context.Background(), httpSrv.URL, rpcclient.Options{}) require.NoError(t, err) t.Cleanup(c.Close) @@ -2446,7 +2450,11 @@ func TestClient_GetVersion_Hardforks(t *testing.T) { v, err := c.GetVersion() require.NoError(t, err) expected := map[config.Hardfork]uint32{ - config.HFAspidochelone: 25, + config.HFAspidochelone: 0, + config.HFBasilisk: 0, + config.HFCockatrice: 0, + config.HFDomovoi: 0, + config.HFEchidna: 0, } require.InDeltaMapValues(t, expected, v.Protocol.Hardforks, 0) } diff --git a/pkg/services/rpcsrv/server_helper_test.go b/pkg/services/rpcsrv/server_helper_test.go index 3595bacd60..c488de8a95 100644 --- a/pkg/services/rpcsrv/server_helper_test.go +++ b/pkg/services/rpcsrv/server_helper_test.go @@ -54,6 +54,7 @@ func getUnitTestChain(t testing.TB, enableOracle bool, enableNotary bool, disabl Password: "one", } } + cfg.ProtocolConfiguration.Hardforks = nil }) } func getUnitTestChainWithCustomConfig(t testing.TB, enableOracle bool, enableNotary bool, customCfg func(configuration *config.Config)) (*core.Blockchain, OracleHandler, config.Config, *zap.Logger) { diff --git a/pkg/services/rpcsrv/server_test.go b/pkg/services/rpcsrv/server_test.go index e6223d602e..1081019982 100644 --- a/pkg/services/rpcsrv/server_test.go +++ b/pkg/services/rpcsrv/server_test.go @@ -74,22 +74,22 @@ type rpcTestCase struct { } const genesisBlockHash = "0f8fb4e17d2ab9f3097af75ca7fd16064160fb8043db94909e00dd4e257b9dc4" -const testContractHash = "565cff9508ebc75aadd7fe59f38dac610ab6093c" -const deploymentTxHash = "a14390941cc3a1d87393eff720a722e9cd350bd6ed233c5fe2001326c80eb68e" +const testContractHash = "449fe8fbd4523072f5e3a4dfa17a494c119d4c08" +const deploymentTxHash = "af170742f0f8a2bc064bdbdb2faa2b517e3df833d4d047da8a946c0b8d581b06" const ( verifyContractHash = "06ed5314c2e4cb103029a60b86d46afa2fb8f67c" verifyContractAVM = "VwIAQS1RCDBwDBTunqIsJ+NL0BSPxBCOCPdOj1BIskrZMCQE2zBxaBPOStkoJATbKGlK2SgkBNsol0A=" - verifyWithArgsContractHash = "4dc916254efd2947c93b11207e8ffc0bb56161c5" - nnsContractHash = "892429fcd47c30f8451781acc627e8b20e0d64f3" + verifyWithArgsContractHash = "6261b3bf753bdc3d24c1327a23fd891e1c8a7ccd" + nnsContractHash = "ebe47d5143bb8726b87b02efb5cd98e21174fd38" nnsToken1ID = "6e656f2e636f6d" - nfsoContractHash = "730ebe719ab8e3b69d11dafc95cdb9bf409db179" + nfsoContractHash = "2f5c1826bb4da1c764a8871427e4044cf3e82dbd" nfsoToken1ID = "7e244ffd6aa85fb1579d2ed22e9b761ab62e3486" storageContractHash = "ebc0c16a76c808cd4dde6bcc063f09e45e331ec7" faultedTxHashLE = "82279bfe9bada282ca0f8cb8e0bb124b921af36f00c69a518320322c6f4fef60" faultedTxBlock uint32 = 23 invokescriptContractAVM = "VwIADBQBDAMOBQYMDQIODw0DDgcJAAAAAErZMCQE2zBwaEH4J+yMqiYEEUAMFA0PAwIJAAIBAwcDBAUCAQAOBgwJStkwJATbMHFpQfgn7IyqJgQSQBNA" - block20StateRootLE = "858c873539d6d24a70f2be13f9dafc61aef2b63c2aa16bb440676de6e44e3cf1" + block20StateRootLE = "b49a35fd3a749fc2f7f4e5fe1f288ef2b6188416f65fe5b691892e8209092082" ) var ( @@ -1381,7 +1381,7 @@ var rpcTestCases = map[string][]rpcTestCase{ script = append(script, 0x41, 0x62, 0x7d, 0x5b, 0x52) return &result.Invoke{ State: "HALT", - GasConsumed: 31922970, + GasConsumed: 31922730, Script: script, Stack: []stackitem.Item{stackitem.Make(true)}, Notifications: []state.NotificationEvent{{ @@ -1411,7 +1411,7 @@ var rpcTestCases = map[string][]rpcTestCase{ chg := []dboper.Operation{{ State: "Changed", Key: []byte{0xfa, 0xff, 0xff, 0xff, 0xb}, - Value: []byte{0x54, 0xb2, 0xd2, 0xa3, 0x51, 0x79, 0x12}, + Value: []byte{0x06, 0x44, 0xda, 0xa3, 0x51, 0x79, 0x12}, }, { State: "Added", Key: []byte{0xfb, 0xff, 0xff, 0xff, 0x14, 0xd6, 0x24, 0x87, 0x12, 0xff, 0x97, 0x22, 0x80, 0xa0, 0xae, 0xf5, 0x24, 0x1c, 0x96, 0x4d, 0x63, 0x78, 0x29, 0xcd, 0xb}, @@ -1423,7 +1423,7 @@ var rpcTestCases = map[string][]rpcTestCase{ }, { State: "Changed", Key: []byte{0xfa, 0xff, 0xff, 0xff, 0x14, 0xee, 0x9e, 0xa2, 0x2c, 0x27, 0xe3, 0x4b, 0xd0, 0x14, 0x8f, 0xc4, 0x10, 0x8e, 0x8, 0xf7, 0x4e, 0x8f, 0x50, 0x48, 0xb2}, - Value: []byte{0x41, 0x01, 0x21, 0x05, 0x0c, 0x76, 0x4f, 0xdf, 0x08}, + Value: []byte{0x41, 0x01, 0x21, 0x05, 0xf6, 0x64, 0x58, 0xdf, 0x08}, }} // Can be returned in any order. assert.ElementsMatch(t, chg, res.Diagnostics.Changes) @@ -1439,7 +1439,7 @@ var rpcTestCases = map[string][]rpcTestCase{ cryptoHash, _ := e.chain.GetNativeContractScriptHash(nativenames.CryptoLib) return &result.Invoke{ State: "HALT", - GasConsumed: 13970250, + GasConsumed: 13969530, Script: script, Stack: []stackitem.Item{stackitem.Make("1.2.3.4")}, Notifications: []state.NotificationEvent{}, @@ -1532,7 +1532,7 @@ var rpcTestCases = map[string][]rpcTestCase{ script = append(script, 0x41, 0x62, 0x7d, 0x5b, 0x52) return &result.Invoke{ State: "HALT", - GasConsumed: 31922970, + GasConsumed: 31922730, Script: script, Stack: []stackitem.Item{stackitem.Make(true)}, Notifications: []state.NotificationEvent{{ @@ -1558,7 +1558,7 @@ var rpcTestCases = map[string][]rpcTestCase{ cryptoHash, _ := e.chain.GetNativeContractScriptHash(nativenames.CryptoLib) return &result.Invoke{ State: "HALT", - GasConsumed: 13970250, + GasConsumed: 13969530, Script: script, Stack: []stackitem.Item{stackitem.Make("1.2.3.4")}, Notifications: []state.NotificationEvent{}, @@ -3260,7 +3260,7 @@ func testRPCProtocol(t *testing.T, doRPCCall func(string, string, *testing.T) [] t.Run("contract-based verification with parameters", func(t *testing.T) { verAcc, err := util.Uint160DecodeStringLE(verifyWithArgsContractHash) require.NoError(t, err) - checkContract(t, verAcc, []byte{}, 244130) // No C# match, but we believe it's OK and it differs from the one above. + checkContract(t, verAcc, []byte{}, 244010) // No C# match, but we believe it's OK and it differs from the one above. }) t.Run("contract-based verification with invocation script", func(t *testing.T) { verAcc, err := util.Uint160DecodeStringLE(verifyWithArgsContractHash) @@ -3270,7 +3270,7 @@ func testRPCProtocol(t *testing.T, doRPCCall func(string, string, *testing.T) [] emit.Int(invocWriter.BinWriter, 5) emit.String(invocWriter.BinWriter, "") invocScript := invocWriter.Bytes() - checkContract(t, verAcc, invocScript, 146960) // No C# match, but we believe it's OK and it has a specific invocation script overriding anything server-side. + checkContract(t, verAcc, invocScript, 146840) // No C# match, but we believe it's OK and it has a specific invocation script overriding anything server-side. }) t.Run("execution limit, ok", func(t *testing.T) { // 1_4000_0000 GAS with the default 1.5 allowed by Policy @@ -3575,7 +3575,7 @@ func checkNep17Balances(t *testing.T, e *executor, acc any) { }, { Asset: e.chain.UtilityTokenHash(), - Amount: "37106285100", + Amount: "37106870550", LastUpdated: 23, Decimals: 8, Name: "GasToken", diff --git a/pkg/services/rpcsrv/testdata/testblocks.acc b/pkg/services/rpcsrv/testdata/testblocks.acc index 173d18a8ce..9f97e713f7 100644 Binary files a/pkg/services/rpcsrv/testdata/testblocks.acc and b/pkg/services/rpcsrv/testdata/testblocks.acc differ