aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorWei-Ning Huang <w@dexon.org>2019-05-19 21:12:55 +0800
committerWei-Ning Huang <w@byzantine-lab.io>2019-09-17 16:57:29 +0800
commit5893ab04fe50d5712bba896c6f6b166b4762b4da (patch)
tree107aa9b4893536be6ea1e215e600ac55259593b0
parent29c18926ca71d545805310748d6f9ce3576ec2b0 (diff)
downloadgo-tangerine-5893ab04fe50d5712bba896c6f6b166b4762b4da.tar.gz
go-tangerine-5893ab04fe50d5712bba896c6f6b166b4762b4da.tar.zst
go-tangerine-5893ab04fe50d5712bba896c6f6b166b4762b4da.zip
core: vm: fix payFine function
-rw-r--r--core/vm/oracle_contracts.go4
-rw-r--r--core/vm/oracle_contracts_test.go8
2 files changed, 11 insertions, 1 deletions
diff --git a/core/vm/oracle_contracts.go b/core/vm/oracle_contracts.go
index 47a680455..eebfa9a3a 100644
--- a/core/vm/oracle_contracts.go
+++ b/core/vm/oracle_contracts.go
@@ -1919,7 +1919,9 @@ func (g *GovernanceContract) payFine(nodeAddr common.Address) ([]byte, error) {
g.state.UpdateNode(nodeOffset, node)
// Pay the fine to governance owner.
- g.evm.StateDB.AddBalance(g.state.Owner(), g.contract.Value())
+ if !g.transfer(GovernanceContractAddress, g.state.Owner(), g.contract.Value()) {
+ return nil, errExecutionReverted
+ }
g.state.emitFinePaid(nodeAddr, g.contract.Value())
diff --git a/core/vm/oracle_contracts_test.go b/core/vm/oracle_contracts_test.go
index 5be893f95..cbf08c273 100644
--- a/core/vm/oracle_contracts_test.go
+++ b/core/vm/oracle_contracts_test.go
@@ -612,11 +612,19 @@ func (g *OracleContractsTestSuite) TestFine() {
g.Require().NotNil(err)
// Pay the fine.
+ govBalance := g.stateDB.GetBalance(GovernanceContractAddress)
+ ownerBalance := g.stateDB.GetBalance(g.config.Owner)
+
input, err = GovernanceABI.ABI.Pack("payFine", addr)
g.Require().NoError(err)
_, err = g.call(GovernanceContractAddress, finePayer, input, amount)
g.Require().NoError(err)
+ g.Require().Equal(g.stateDB.GetBalance(GovernanceContractAddress).String(),
+ govBalance.String())
+ g.Require().Equal(g.stateDB.GetBalance(g.config.Owner).String(),
+ new(big.Int).Add(ownerBalance, amount).String())
+
// Qualified.
g.Require().Equal(1, len(g.s.QualifiedNodes()))
}