From 2f6345f2d9c35490d935bae67428e37a63ebf6e5 Mon Sep 17 00:00:00 2001 From: Evgeniy Stratonikov Date: Mon, 8 Feb 2021 11:10:58 +0300 Subject: [PATCH] compiler: add Hash compatibility test --- pkg/compiler/native_test.go | 30 +++++++++++++++++++++++++++ pkg/core/native/compatibility_test.go | 13 ------------ 2 files changed, 30 insertions(+), 13 deletions(-) diff --git a/pkg/compiler/native_test.go b/pkg/compiler/native_test.go index b3de8fb15..78a6c14b8 100644 --- a/pkg/compiler/native_test.go +++ b/pkg/compiler/native_test.go @@ -1,14 +1,44 @@ package compiler_test import ( + "fmt" "testing" "github.com/nspcc-dev/neo-go/pkg/core/native" + "github.com/nspcc-dev/neo-go/pkg/interop/native/gas" + "github.com/nspcc-dev/neo-go/pkg/interop/native/ledger" "github.com/nspcc-dev/neo-go/pkg/interop/native/nameservice" + "github.com/nspcc-dev/neo-go/pkg/interop/native/neo" + "github.com/nspcc-dev/neo-go/pkg/interop/native/notary" + "github.com/nspcc-dev/neo-go/pkg/interop/native/oracle" + "github.com/nspcc-dev/neo-go/pkg/interop/native/policy" "github.com/nspcc-dev/neo-go/pkg/interop/native/roles" + "github.com/nspcc-dev/neo-go/pkg/util" "github.com/stretchr/testify/require" ) +func TestContractHashes(t *testing.T) { + cs := native.NewContracts(true) + require.Equal(t, []byte(neo.Hash), cs.NEO.Hash.BytesBE()) + require.Equal(t, []byte(gas.Hash), cs.GAS.Hash.BytesBE()) + require.Equal(t, []byte(oracle.Hash), cs.Oracle.Hash.BytesBE()) + require.Equal(t, []byte(roles.Hash), cs.Designate.Hash.BytesBE()) + require.Equal(t, []byte(policy.Hash), cs.Policy.Hash.BytesBE()) + require.Equal(t, []byte(nameservice.Hash), cs.NameService.Hash.BytesBE()) + require.Equal(t, []byte(ledger.Hash), cs.Ledger.Hash.BytesBE()) + require.Equal(t, []byte(management.Hash), cs.Management.Hash.BytesBE()) + require.Equal(t, []byte(notary.Hash), cs.Notary.Hash.BytesBE()) +} + +// testPrintHash is a helper for updating contract hashes. +func testPrintHash(u util.Uint160) { + fmt.Print(`"`) + for _, b := range u.BytesBE() { + fmt.Printf("\\x%02x", b) + } + fmt.Println(`"`) +} + func TestRoleManagementRole(t *testing.T) { require.EqualValues(t, native.RoleOracle, roles.Oracle) require.EqualValues(t, native.RoleStateValidator, roles.StateValidator) diff --git a/pkg/core/native/compatibility_test.go b/pkg/core/native/compatibility_test.go index 5e0c7b471..d055628be 100644 --- a/pkg/core/native/compatibility_test.go +++ b/pkg/core/native/compatibility_test.go @@ -7,19 +7,6 @@ import ( "github.com/stretchr/testify/require" ) -// Compatibility test. hashes are taken directly from C# node. -func TestNativeHashes(t *testing.T) { - require.Equal(t, "a501d7d7d10983673b61b7a2d3a813b36f9f0e43", newManagement().Hash.StringLE()) - require.Equal(t, "971d69c6dd10ce88e7dfffec1dc603c6125a8764", newLedger().Hash.StringLE()) - require.Equal(t, "f61eebf573ea36593fd43aa150c055ad7906ab83", newNEO().Hash.StringLE()) - require.Equal(t, "70e2301955bf1e74cbb31d18c2f96972abadb328", newGAS().Hash.StringLE()) - require.Equal(t, "79bcd398505eb779df6e67e4be6c14cded08e2f2", newPolicy().Hash.StringLE()) - require.Equal(t, "597b1471bbce497b7809e2c8f10db67050008b02", newDesignate(false).Hash.StringLE()) - require.Equal(t, "8dc0e742cbdfdeda51ff8a8b78d46829144c80ee", newOracle().Hash.StringLE()) - // Not yet a part of NEO. - //require.Equal(t, "", newNotary().Hash.StringLE()()) -} - // "C" and "O" can easily be typed by accident. func TestNamesASCII(t *testing.T) { cs := NewContracts(true)