diff options
author | Wei-Ning Huang <w@dexon.org> | 2019-04-19 12:33:23 +0800 |
---|---|---|
committer | Wei-Ning Huang <w@byzantine-lab.io> | 2019-06-15 22:09:56 +0800 |
commit | 3f433c2137aaf4cd972009cf61bf325f6a1ad2d3 (patch) | |
tree | d3fa0b9830c9e13ced1b1e97df549955ae5454ab | |
parent | c17a0ebe45958741d84942f6dc71f0d8050252d1 (diff) | |
download | go-tangerine-3f433c2137aaf4cd972009cf61bf325f6a1ad2d3.tar go-tangerine-3f433c2137aaf4cd972009cf61bf325f6a1ad2d3.tar.gz go-tangerine-3f433c2137aaf4cd972009cf61bf325f6a1ad2d3.tar.bz2 go-tangerine-3f433c2137aaf4cd972009cf61bf325f6a1ad2d3.tar.lz go-tangerine-3f433c2137aaf4cd972009cf61bf325f6a1ad2d3.tar.xz go-tangerine-3f433c2137aaf4cd972009cf61bf325f6a1ad2d3.tar.zst go-tangerine-3f433c2137aaf4cd972009cf61bf325f6a1ad2d3.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 899128493..90cef5def 100644 --- a/core/vm/oracle_contracts.go +++ b/core/vm/oracle_contracts.go @@ -2656,7 +2656,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) @@ -2682,7 +2682,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 a7680b69e..be1e2a27d 100644 --- a/core/vm/oracle_contracts_test.go +++ b/core/vm/oracle_contracts_test.go @@ -277,7 +277,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") @@ -285,8 +284,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) @@ -294,7 +291,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) @@ -307,10 +303,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) @@ -337,8 +332,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) @@ -353,7 +346,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() { |