Skip to content

Commit

Permalink
Merge pull request #598 from okex/fix-precision-error
Browse files Browse the repository at this point in the history
fix precision error during refund gas
  • Loading branch information
KamiD authored Jan 26, 2021
2 parents fbd5a75 + 1aaeb0c commit ed53308
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
7 changes: 4 additions & 3 deletions x/evm/handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@ import (
"crypto/ecdsa"
"encoding/json"
"fmt"
"github.com/cosmos/cosmos-sdk/x/supply"
"math/big"
"strings"
"testing"
"time"

"github.com/cosmos/cosmos-sdk/x/supply"

"github.com/status-im/keycard-go/hexutils"

"github.com/stretchr/testify/suite"
Expand Down Expand Up @@ -639,7 +640,7 @@ func (suite *EvmTestSuite) TestRefundGas() {
balanceAfterHandler := big.NewInt(1).Sub(userBalance, tc.consumed)
balanceAfterRefund := suite.app.EvmKeeper.GetBalance(suite.ctx, sender)

suite.Require().Equal(big.NewInt(1).Mul(gasRefund, big.NewInt(1000000000000000000)), big.NewInt(1).Sub(balanceAfterRefund, balanceAfterHandler))
suite.Require().Equal(big.NewInt(1).Mul(gasRefund, big.NewInt(1)), big.NewInt(1).Sub(balanceAfterRefund, balanceAfterHandler))
})
}
}
}
5 changes: 3 additions & 2 deletions x/evm/types/state_transition.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@ package types
import (
"errors"
"fmt"
"github.com/cosmos/cosmos-sdk/x/auth/types"
"math/big"
"strings"

"github.com/cosmos/cosmos-sdk/x/auth/types"

"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core"
ethtypes "github.com/ethereum/go-ethereum/core/types"
Expand Down Expand Up @@ -309,7 +310,7 @@ func (st StateTransition) RefundGas(ctx sdk.Context) error {
ctx.WithGasMeter(sdk.NewInfiniteGasMeter()),
types.FeeCollectorName,
senderAddress,
sdk.NewCoins(sdk.NewCoin(st.CoinDenom, sdk.NewIntFromBigInt(feeReturn))),
sdk.NewCoins(sdk.NewCoin(st.CoinDenom, sdk.NewDecFromBigIntWithPrec(feeReturn, sdk.Precision))),
); err != nil {
return err
}
Expand Down

0 comments on commit ed53308

Please sign in to comment.