Skip to content

Commit

Permalink
core: move Notary contract under Domovoi hardfork
Browse files Browse the repository at this point in the history
Close #3464. Adjust tests, enable all hardforks for RPC server tests
starting from genesis.

Signed-off-by: Anna Shaleva <[email protected]>
  • Loading branch information
AnnaShaleva committed Jul 15, 2024
1 parent b2ac71e commit 4eadc2c
Show file tree
Hide file tree
Showing 8 changed files with 161 additions and 31 deletions.
7 changes: 7 additions & 0 deletions internal/basicchain/basic.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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"))
Expand Down
2 changes: 1 addition & 1 deletion pkg/core/blockchain_neotest_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
135 changes: 123 additions & 12 deletions pkg/core/native/native_test/management_test.go

Large diffs are not rendered by default.

7 changes: 5 additions & 2 deletions pkg/core/native/notary.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down
10 changes: 9 additions & 1 deletion pkg/services/rpcsrv/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
}
1 change: 1 addition & 0 deletions pkg/services/rpcsrv/server_helper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
30 changes: 15 additions & 15 deletions pkg/services/rpcsrv/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down Expand Up @@ -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{{
Expand Down Expand Up @@ -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},
Expand All @@ -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)
Expand All @@ -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{},
Expand Down Expand Up @@ -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{{
Expand All @@ -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{},
Expand Down Expand Up @@ -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)
Expand All @@ -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
Expand Down Expand Up @@ -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",
Expand Down
Binary file modified pkg/services/rpcsrv/testdata/testblocks.acc
Binary file not shown.

0 comments on commit 4eadc2c

Please sign in to comment.