diff options
author | Wei-Ning Huang <w@dexon.org> | 2019-04-19 12:33:23 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-04-19 12:33:23 +0800 |
commit | d0eadef743a1b643c263107c99eb6b0bcb118249 (patch) | |
tree | cfc05df506344d3a420d85388f4379a157e72834 | |
parent | 6c00e42f8dfec9e5d0ef8582a0ed8d809b631564 (diff) | |
download | dexon-d0eadef743a1b643c263107c99eb6b0bcb118249.tar.gz dexon-d0eadef743a1b643c263107c99eb6b0bcb118249.tar.zst dexon-d0eadef743a1b643c263107c99eb6b0bcb118249.zip |
core: vm: fix node offset during transfer (#377)
-rw-r--r-- | core/vm/oracle_contracts.go | 4 | ||||
-rw-r--r-- | core/vm/oracle_contracts_test.go | 18 |
2 files changed, 9 insertions, 13 deletions
diff --git a/core/vm/oracle_contracts.go b/core/vm/oracle_contracts.go index a6e283abe..2dc1ce54f 100644 --- a/core/vm/oracle_contracts.go +++ b/core/vm/oracle_contracts.go @@ -2658,7 +2658,7 @@ func (g *GovernanceContract) transferNodeOwnership(newOwner common.Address) ([]b } node := g.state.Node(offset) - g.state.PutNodeOffsets(node, big.NewInt(0)) + g.state.DeleteNodeOffsets(node) node.Owner = newOwner g.state.PutNodeOffsets(node, offset) @@ -2684,7 +2684,7 @@ func (g *GovernanceContract) replaceNodePublicKey(newPublicKey []byte) ([]byte, return nil, errExecutionReverted } - g.state.PutNodeOffsets(node, big.NewInt(0)) + g.state.DeleteNodeOffsets(node) node.PublicKey = newPublicKey g.state.PutNodeOffsets(node, offset) diff --git a/core/vm/oracle_contracts_test.go b/core/vm/oracle_contracts_test.go index 15a519eba..94c2828ad 100644 --- a/core/vm/oracle_contracts_test.go +++ b/core/vm/oracle_contracts_test.go @@ -278,7 +278,6 @@ func (g *OracleContractsTestSuite) TestTransferOwnership() { func (g *OracleContractsTestSuite) TestTransferNodeOwnership() { privKey, addr := newPrefundAccount(g.stateDB) pk := crypto.FromECDSAPub(&privKey.PublicKey) - nodeKeyAddr := crypto.PubkeyToAddress(privKey.PublicKey) amount := new(big.Int).Mul(big.NewInt(1e18), big.NewInt(1e6)) input, err := GovernanceABI.ABI.Pack("register", pk, "Test1", "test1@dexon.org", "Taipei", "https://dexon.org") @@ -286,8 +285,6 @@ func (g *OracleContractsTestSuite) TestTransferNodeOwnership() { _, err = g.call(GovernanceContractAddress, addr, input, amount) g.Require().NoError(err) - offset := g.s.NodesOffsetByAddress(addr) - // Call with not valid new owner. input, err = GovernanceABI.ABI.Pack("transferNodeOwnership", common.Address{}) g.Require().NoError(err) @@ -295,7 +292,6 @@ func (g *OracleContractsTestSuite) TestTransferNodeOwnership() { g.Require().NotNil(err) _, newAddr := newPrefundAccount(g.stateDB) - newNodeKeyAddr := crypto.PubkeyToAddress(privKey.PublicKey) input, err = GovernanceABI.ABI.Pack("transferNodeOwnership", newAddr) g.Require().NoError(err) @@ -308,10 +304,9 @@ func (g *OracleContractsTestSuite) TestTransferNodeOwnership() { // Call with owner. _, err = g.call(GovernanceContractAddress, addr, input, big.NewInt(0)) g.Require().NoError(err) - g.Require().Equal(uint64(0), g.s.NodesOffsetByAddress(addr).Uint64()) - g.Require().Equal(uint64(0), g.s.NodesOffsetByNodeKeyAddress(nodeKeyAddr).Uint64()) - g.Require().Equal(offset.Uint64(), g.s.NodesOffsetByAddress(newAddr).Uint64()) - g.Require().Equal(offset.Uint64(), g.s.NodesOffsetByNodeKeyAddress(newNodeKeyAddr).Uint64()) + g.Require().Equal(-1, int(g.s.NodesOffsetByAddress(addr).Int64())) + g.Require().Equal(0, int(g.s.NodesOffsetByNodeKeyAddress(addr).Int64())) + g.Require().Equal(0, int(g.s.NodesOffsetByAddress(newAddr).Int64())) // New node for duplication test. privKey2, addr2 := newPrefundAccount(g.stateDB) @@ -338,8 +333,6 @@ func (g *OracleContractsTestSuite) TestReplaceNodePublicKey() { _, err = g.call(GovernanceContractAddress, addr, input, amount) g.Require().NoError(err) - offset := g.s.NodesOffsetByAddress(addr) - privKey2, addr2 := newPrefundAccount(g.stateDB) pk2 := crypto.FromECDSAPub(&privKey2.PublicKey) @@ -354,7 +347,10 @@ func (g *OracleContractsTestSuite) TestReplaceNodePublicKey() { // Call with owner. _, err = g.call(GovernanceContractAddress, addr, input, big.NewInt(0)) g.Require().NoError(err) - g.Require().Equal(offset.Uint64(), g.s.NodesOffsetByNodeKeyAddress(addr2).Uint64()) + + g.Require().Equal(-1, int(g.s.NodesOffsetByNodeKeyAddress(addr).Int64())) + g.Require().Equal(0, int(g.s.NodesOffsetByAddress(addr).Int64())) + g.Require().Equal(0, int(g.s.NodesOffsetByNodeKeyAddress(addr2).Int64())) } func (g *OracleContractsTestSuite) TestStakingMechanism() { |