rpc: fix balance overflow (#219)

Closes #218
This commit is contained in:
yihuang
2021-07-02 05:29:47 -04:00
committed by GitHub
parent f7d975ada2
commit 6e983a9da1
8 changed files with 408 additions and 187 deletions
+2 -2
View File
@@ -36,7 +36,7 @@ func (k Keeper) Account(c context.Context, req *types.QueryAccountRequest) (*typ
k.WithContext(ctx)
return &types.QueryAccountResponse{
Balance: k.GetBalance(addr).Int64(),
Balance: k.GetBalance(addr).String(),
CodeHash: k.GetCodeHash(addr).Hex(),
Nonce: k.GetNonce(addr),
}, nil
@@ -127,7 +127,7 @@ func (k Keeper) Balance(c context.Context, req *types.QueryBalanceRequest) (*typ
balanceInt := k.GetBalance(ethcmn.HexToAddress(req.Address))
return &types.QueryBalanceResponse{
Balance: balanceInt.Int64(),
Balance: balanceInt.String(),
}, nil
}
+5 -5
View File
@@ -36,7 +36,7 @@ func (suite *KeeperTestSuite) TestQueryAccount() {
"invalid address",
func() {
expAccount = &types.QueryAccountResponse{
Balance: 0,
Balance: "0",
CodeHash: common.BytesToHash(ethcrypto.Keccak256(nil)).Hex(),
Nonce: 0,
}
@@ -56,7 +56,7 @@ func (suite *KeeperTestSuite) TestQueryAccount() {
suite.Require().NoError(err)
expAccount = &types.QueryAccountResponse{
Balance: 100,
Balance: "100",
CodeHash: common.BytesToHash(ethcrypto.Keccak256(nil)).Hex(),
Nonce: 0,
}
@@ -168,7 +168,7 @@ func (suite *KeeperTestSuite) TestQueryCosmosAccount() {
func (suite *KeeperTestSuite) TestQueryBalance() {
var (
req *types.QueryBalanceRequest
expBalance int64
expBalance string
)
testCases := []struct {
@@ -178,7 +178,7 @@ func (suite *KeeperTestSuite) TestQueryBalance() {
}{
{"invalid address",
func() {
expBalance = 0
expBalance = "0"
req = &types.QueryBalanceRequest{
Address: invalidAddress,
}
@@ -194,7 +194,7 @@ func (suite *KeeperTestSuite) TestQueryBalance() {
err = suite.app.BankKeeper.SendCoinsFromModuleToAccount(suite.ctx, types.ModuleName, suite.address.Bytes(), amt)
suite.Require().NoError(err)
expBalance = 100
expBalance = "100"
req = &types.QueryBalanceRequest{
Address: suite.address.String(),
}