Skip to content

Commit c4a324d

Browse files
committed
core: move Notary contract under Domovoi hardfork
Close #3464. Adjust tests, enable all hardforks for RPC server tests starting from genesis. Signed-off-by: Anna Shaleva <shaleva.ann@nspcc.ru>
1 parent 49e51a4 commit c4a324d

File tree

8 files changed

+158
-31
lines changed

8 files changed

+158
-31
lines changed

internal/basicchain/basic.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"path/filepath"
99
"testing"
1010

11+
"github.com/nspcc-dev/neo-go/pkg/config"
1112
"github.com/nspcc-dev/neo-go/pkg/core/native"
1213
"github.com/nspcc-dev/neo-go/pkg/core/native/nativenames"
1314
"github.com/nspcc-dev/neo-go/pkg/core/native/noderoles"
@@ -81,6 +82,11 @@ func Init(t *testing.T, rootpath string, e *neotest.Executor) {
8182
t.Fatal("P2PSigExtensions should be enabled to init basic chain")
8283
}
8384

85+
const notaryDepositHeight uint32 = 8
86+
domovoiH, ok := e.Chain.GetConfig().Hardforks[config.HFDomovoi.String()]
87+
require.Truef(t, ok, "%s hardfork should be enabled since basic chain uses Notary contract", config.HFDomovoi.String())
88+
require.LessOrEqualf(t, domovoiH, notaryDepositHeight-1, "%s hardfork should be enabled starting from height %d, got: %d", config.HFDomovoi.String(), notaryDepositHeight-1, domovoiH)
89+
8490
var (
8591
// examplesPrefix is a prefix of the example smart-contracts.
8692
examplesPrefix = filepath.Join(rootpath, "examples")
@@ -189,6 +195,7 @@ func Init(t *testing.T, rootpath string, e *neotest.Executor) {
189195
// Block #8: deposit some GAS to notary contract for priv0.
190196
transferTxH = gasPriv0Invoker.Invoke(t, true, "transfer", priv0ScriptHash, notaryHash, 10_0000_0000, []any{priv0ScriptHash, int64(e.Chain.BlockHeight() + 1000)})
191197
t.Logf("notaryDepositTxPriv0: %v", transferTxH.StringLE())
198+
require.Equal(t, uint32(notaryDepositHeight), e.Chain.BlockHeight(), "notaryDepositHeight constant is out of date")
192199

193200
// Block #9: designate new Notary node.
194201
ntr, err := wallet.NewWalletFromFile(path.Join(notaryModulePath, "./testdata/notary1.json"))

pkg/core/blockchain_neotest_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2572,7 +2572,7 @@ func TestBlockchain_GenesisTransactionExtension(t *testing.T) {
25722572
// in the right order.
25732573
func TestNativenames(t *testing.T) {
25742574
bc, _ := chain.NewSingleWithCustomConfig(t, func(cfg *config.Blockchain) {
2575-
cfg.Hardforks = map[string]uint32{}
2575+
cfg.Hardforks = nil // default (all hardforks enabled) behaviour.
25762576
cfg.P2PSigExtensions = true
25772577
})
25782578
natives := bc.GetNatives()

pkg/core/native/native_test/management_test.go

Lines changed: 121 additions & 12 deletions
Large diffs are not rendered by default.

pkg/core/native/notary.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,10 @@ const (
5252
defaultMaxNotValidBeforeDelta = 140 // 20 rounds for 7 validators, a little more than half an hour
5353
)
5454

55-
var maxNotValidBeforeDeltaKey = []byte{10}
55+
var (
56+
maxNotValidBeforeDeltaKey = []byte{10}
57+
activeIn = config.HFDomovoi
58+
)
5659

5760
var (
5861
_ interop.Contract = (*Notary)(nil)
@@ -200,7 +203,7 @@ func (n *Notary) PostPersist(ic *interop.Context) error {
200203

201204
// ActiveIn implements the Contract interface.
202205
func (n *Notary) ActiveIn() *config.Hardfork {
203-
return nil
206+
return &activeIn
204207
}
205208

206209
// onPayment records the deposited amount as belonging to "from" address with a lock

pkg/services/rpcsrv/client_test.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -465,6 +465,10 @@ func TestClientNEOContract(t *testing.T) {
465465
func TestClientNotary(t *testing.T) {
466466
chain, _, httpSrv := initServerWithInMemoryChain(t)
467467

468+
// Domovoi should be enabled since this test uses Notary contract.
469+
_, ok := chain.GetConfig().Hardforks[config.HFDomovoi.String()]
470+
require.True(t, ok)
471+
468472
c, err := rpcclient.New(context.Background(), httpSrv.URL, rpcclient.Options{})
469473
require.NoError(t, err)
470474
t.Cleanup(c.Close)
@@ -2446,7 +2450,10 @@ func TestClient_GetVersion_Hardforks(t *testing.T) {
24462450
v, err := c.GetVersion()
24472451
require.NoError(t, err)
24482452
expected := map[config.Hardfork]uint32{
2449-
config.HFAspidochelone: 25,
2453+
config.HFAspidochelone: 0,
2454+
config.HFBasilisk: 0,
2455+
config.HFCockatrice: 0,
2456+
config.HFDomovoi: 0,
24502457
}
24512458
require.InDeltaMapValues(t, expected, v.Protocol.Hardforks, 0)
24522459
}

pkg/services/rpcsrv/server_helper_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ func getUnitTestChain(t testing.TB, enableOracle bool, enableNotary bool, disabl
5454
Password: "one",
5555
}
5656
}
57+
cfg.ProtocolConfiguration.Hardforks = nil
5758
})
5859
}
5960
func getUnitTestChainWithCustomConfig(t testing.TB, enableOracle bool, enableNotary bool, customCfg func(configuration *config.Config)) (*core.Blockchain, OracleHandler, config.Config, *zap.Logger) {

pkg/services/rpcsrv/server_test.go

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -74,22 +74,22 @@ type rpcTestCase struct {
7474
}
7575

7676
const genesisBlockHash = "0f8fb4e17d2ab9f3097af75ca7fd16064160fb8043db94909e00dd4e257b9dc4"
77-
const testContractHash = "565cff9508ebc75aadd7fe59f38dac610ab6093c"
78-
const deploymentTxHash = "a14390941cc3a1d87393eff720a722e9cd350bd6ed233c5fe2001326c80eb68e"
77+
const testContractHash = "449fe8fbd4523072f5e3a4dfa17a494c119d4c08"
78+
const deploymentTxHash = "af170742f0f8a2bc064bdbdb2faa2b517e3df833d4d047da8a946c0b8d581b06"
7979

8080
const (
8181
verifyContractHash = "06ed5314c2e4cb103029a60b86d46afa2fb8f67c"
8282
verifyContractAVM = "VwIAQS1RCDBwDBTunqIsJ+NL0BSPxBCOCPdOj1BIskrZMCQE2zBxaBPOStkoJATbKGlK2SgkBNsol0A="
83-
verifyWithArgsContractHash = "4dc916254efd2947c93b11207e8ffc0bb56161c5"
84-
nnsContractHash = "892429fcd47c30f8451781acc627e8b20e0d64f3"
83+
verifyWithArgsContractHash = "6261b3bf753bdc3d24c1327a23fd891e1c8a7ccd"
84+
nnsContractHash = "ebe47d5143bb8726b87b02efb5cd98e21174fd38"
8585
nnsToken1ID = "6e656f2e636f6d"
86-
nfsoContractHash = "730ebe719ab8e3b69d11dafc95cdb9bf409db179"
86+
nfsoContractHash = "2f5c1826bb4da1c764a8871427e4044cf3e82dbd"
8787
nfsoToken1ID = "7e244ffd6aa85fb1579d2ed22e9b761ab62e3486"
8888
storageContractHash = "ebc0c16a76c808cd4dde6bcc063f09e45e331ec7"
8989
faultedTxHashLE = "82279bfe9bada282ca0f8cb8e0bb124b921af36f00c69a518320322c6f4fef60"
9090
faultedTxBlock uint32 = 23
9191
invokescriptContractAVM = "VwIADBQBDAMOBQYMDQIODw0DDgcJAAAAAErZMCQE2zBwaEH4J+yMqiYEEUAMFA0PAwIJAAIBAwcDBAUCAQAOBgwJStkwJATbMHFpQfgn7IyqJgQSQBNA"
92-
block20StateRootLE = "858c873539d6d24a70f2be13f9dafc61aef2b63c2aa16bb440676de6e44e3cf1"
92+
block20StateRootLE = "b49a35fd3a749fc2f7f4e5fe1f288ef2b6188416f65fe5b691892e8209092082"
9393
)
9494

9595
var (
@@ -1381,7 +1381,7 @@ var rpcTestCases = map[string][]rpcTestCase{
13811381
script = append(script, 0x41, 0x62, 0x7d, 0x5b, 0x52)
13821382
return &result.Invoke{
13831383
State: "HALT",
1384-
GasConsumed: 31922970,
1384+
GasConsumed: 31922730,
13851385
Script: script,
13861386
Stack: []stackitem.Item{stackitem.Make(true)},
13871387
Notifications: []state.NotificationEvent{{
@@ -1411,7 +1411,7 @@ var rpcTestCases = map[string][]rpcTestCase{
14111411
chg := []dboper.Operation{{
14121412
State: "Changed",
14131413
Key: []byte{0xfa, 0xff, 0xff, 0xff, 0xb},
1414-
Value: []byte{0x54, 0xb2, 0xd2, 0xa3, 0x51, 0x79, 0x12},
1414+
Value: []byte{0x06, 0x44, 0xda, 0xa3, 0x51, 0x79, 0x12},
14151415
}, {
14161416
State: "Added",
14171417
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{
14231423
}, {
14241424
State: "Changed",
14251425
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},
1426-
Value: []byte{0x41, 0x01, 0x21, 0x05, 0x0c, 0x76, 0x4f, 0xdf, 0x08},
1426+
Value: []byte{0x41, 0x01, 0x21, 0x05, 0xf6, 0x64, 0x58, 0xdf, 0x08},
14271427
}}
14281428
// Can be returned in any order.
14291429
assert.ElementsMatch(t, chg, res.Diagnostics.Changes)
@@ -1439,7 +1439,7 @@ var rpcTestCases = map[string][]rpcTestCase{
14391439
cryptoHash, _ := e.chain.GetNativeContractScriptHash(nativenames.CryptoLib)
14401440
return &result.Invoke{
14411441
State: "HALT",
1442-
GasConsumed: 13970250,
1442+
GasConsumed: 13969530,
14431443
Script: script,
14441444
Stack: []stackitem.Item{stackitem.Make("1.2.3.4")},
14451445
Notifications: []state.NotificationEvent{},
@@ -1532,7 +1532,7 @@ var rpcTestCases = map[string][]rpcTestCase{
15321532
script = append(script, 0x41, 0x62, 0x7d, 0x5b, 0x52)
15331533
return &result.Invoke{
15341534
State: "HALT",
1535-
GasConsumed: 31922970,
1535+
GasConsumed: 31922730,
15361536
Script: script,
15371537
Stack: []stackitem.Item{stackitem.Make(true)},
15381538
Notifications: []state.NotificationEvent{{
@@ -1558,7 +1558,7 @@ var rpcTestCases = map[string][]rpcTestCase{
15581558
cryptoHash, _ := e.chain.GetNativeContractScriptHash(nativenames.CryptoLib)
15591559
return &result.Invoke{
15601560
State: "HALT",
1561-
GasConsumed: 13970250,
1561+
GasConsumed: 13969530,
15621562
Script: script,
15631563
Stack: []stackitem.Item{stackitem.Make("1.2.3.4")},
15641564
Notifications: []state.NotificationEvent{},
@@ -3260,7 +3260,7 @@ func testRPCProtocol(t *testing.T, doRPCCall func(string, string, *testing.T) []
32603260
t.Run("contract-based verification with parameters", func(t *testing.T) {
32613261
verAcc, err := util.Uint160DecodeStringLE(verifyWithArgsContractHash)
32623262
require.NoError(t, err)
3263-
checkContract(t, verAcc, []byte{}, 244130) // No C# match, but we believe it's OK and it differs from the one above.
3263+
checkContract(t, verAcc, []byte{}, 244010) // No C# match, but we believe it's OK and it differs from the one above.
32643264
})
32653265
t.Run("contract-based verification with invocation script", func(t *testing.T) {
32663266
verAcc, err := util.Uint160DecodeStringLE(verifyWithArgsContractHash)
@@ -3270,7 +3270,7 @@ func testRPCProtocol(t *testing.T, doRPCCall func(string, string, *testing.T) []
32703270
emit.Int(invocWriter.BinWriter, 5)
32713271
emit.String(invocWriter.BinWriter, "")
32723272
invocScript := invocWriter.Bytes()
3273-
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.
3273+
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.
32743274
})
32753275
t.Run("execution limit, ok", func(t *testing.T) {
32763276
// 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) {
35753575
},
35763576
{
35773577
Asset: e.chain.UtilityTokenHash(),
3578-
Amount: "37106285100",
3578+
Amount: "37106870550",
35793579
LastUpdated: 23,
35803580
Decimals: 8,
35813581
Name: "GasToken",
-90 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)