Skip to content

Commit f04ddfe

Browse files
committed
cleanup bank test
1 parent c8b7c01 commit f04ddfe

File tree

2 files changed

+54
-69
lines changed

2 files changed

+54
-69
lines changed

tests/integration/precompiles/bank/test_integration.go

Lines changed: 54 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -170,14 +170,15 @@ func TestIntegrationSuite(t *testing.T, create network.CreateEvmApp, options ...
170170
_, ethRes, err := is.factory.CallContractAndCheckLogs(sender.Priv, queryArgs, balancesArgs, passCheck)
171171
Expect(err).ToNot(HaveOccurred(), "unexpected result calling contract")
172172

173-
balances, err := decodeBalancesResult(ethRes.Ret)
173+
var ret bank2.BalancesReturn
174+
_, err = ret.Decode(ethRes.Ret)
174175
Expect(err).ToNot(HaveOccurred(), "failed to unpack balances")
175176

176177
balanceAfter, err := is.grpcHandler.GetBalanceFromBank(receiver.Bytes(), is.tokenDenom)
177178
Expect(err).ToNot(HaveOccurred(), "failed to get balance")
178179

179-
Expect(math.NewInt(balances[0].Amount.Int64())).To(Equal(balanceAfter.Balance.Amount))
180-
Expect(*balances[0].Amount).To(Equal(*amount))
180+
Expect(math.NewInt(ret.Balances[0].Amount.Int64())).To(Equal(balanceAfter.Balance.Amount))
181+
Expect(*ret.Balances[0].Amount).To(Equal(*amount))
181182
})
182183

183184
It("should return a single token balance", func() {
@@ -192,25 +193,27 @@ func TestIntegrationSuite(t *testing.T, create network.CreateEvmApp, options ...
192193
_, ethRes, err := is.factory.CallContractAndCheckLogs(sender.Priv, queryArgs, balancesArgs, passCheck)
193194
Expect(err).ToNot(HaveOccurred(), "unexpected result calling contract")
194195

195-
balances, err := decodeBalancesResult(ethRes.Ret)
196+
var ret bank2.BalancesReturn
197+
_, err = ret.Decode(ethRes.Ret)
196198
Expect(err).ToNot(HaveOccurred(), "failed to unpack balances")
197199

198200
balanceAfter, err := is.grpcHandler.GetBalanceFromBank(receiver.Bytes(), is.network.GetBaseDenom())
199201
Expect(err).ToNot(HaveOccurred(), "failed to get balance")
200202

201-
Expect(math.NewInt(balances[0].Amount.Int64())).To(Equal(balanceAfter.Balance.Amount))
202-
Expect(*balances[0].Amount).To(Equal(*amount))
203+
Expect(math.NewInt(ret.Balances[0].Amount.Int64())).To(Equal(balanceAfter.Balance.Amount))
204+
Expect(*ret.Balances[0].Amount).To(Equal(*amount))
203205
})
204206

205207
It("should return no balance for new account", func() {
206208
queryArgs, balancesArgs := getTxAndCallArgs(directCall, contractData, bank2.BalancesMethod, utiltx.GenerateAddress())
207209
_, ethRes, err := is.factory.CallContractAndCheckLogs(sender.Priv, queryArgs, balancesArgs, passCheck)
208210
Expect(err).ToNot(HaveOccurred(), "unexpected result calling contract")
209211

210-
balances, err := decodeBalancesResult(ethRes.Ret)
212+
var ret bank2.BalancesReturn
213+
_, err = ret.Decode(ethRes.Ret)
211214
Expect(err).ToNot(HaveOccurred(), "failed to unpack balances")
212215

213-
Expect(balances).To(BeEmpty())
216+
Expect(ret.Balances).To(BeEmpty())
214217
})
215218

216219
It("should consume the correct amount of gas", func() {
@@ -221,10 +224,11 @@ func TestIntegrationSuite(t *testing.T, create network.CreateEvmApp, options ...
221224
ethRes, err := evmtypes.DecodeTxResponse(res.Data)
222225
Expect(err).ToNot(HaveOccurred(), "failed to decode tx response")
223226

224-
balances, err := decodeBalancesResult(ethRes.Ret)
227+
var ret bank2.BalancesReturn
228+
_, err = ret.Decode(ethRes.Ret)
225229
Expect(err).ToNot(HaveOccurred(), "failed to unpack balances")
226230

227-
gasUsed := Max(bank2.GasBalances, len(balances)*bank2.GasBalances)
231+
gasUsed := Max(bank2.GasBalances, len(ret.Balances)*bank2.GasBalances)
228232
// Here increasing the GasBalanceOf will increase the use of gas so they will never be equal
229233
Expect(gasUsed).To(BeNumerically("<=", ethRes.GasUsed))
230234
})
@@ -236,11 +240,12 @@ func TestIntegrationSuite(t *testing.T, create network.CreateEvmApp, options ...
236240
_, ethRes, err := is.factory.CallContractAndCheckLogs(sender.Priv, queryArgs, supplyArgs, passCheck)
237241
Expect(err).ToNot(HaveOccurred(), "unexpected result calling contract")
238242

239-
balances, err := decodeTotalSupplyResult(ethRes.Ret)
243+
var ret bank2.TotalSupplyReturn
244+
_, err = ret.Decode(ethRes.Ret)
240245
Expect(err).ToNot(HaveOccurred(), "failed to unpack balances")
241246

242-
Expect(balances[0].Amount.String()).To(Equal(cosmosEVMTotalSupply.String()))
243-
Expect(balances[1].Amount.String()).To(Equal(xmplTotalSupply.String()))
247+
Expect(ret.TotalSupply[0].Amount.String()).To(Equal(cosmosEVMTotalSupply.String()))
248+
Expect(ret.TotalSupply[1].Amount.String()).To(Equal(xmplTotalSupply.String()))
244249
})
245250
})
246251

@@ -250,32 +255,35 @@ func TestIntegrationSuite(t *testing.T, create network.CreateEvmApp, options ...
250255
_, ethRes, err := is.factory.CallContractAndCheckLogs(sender.Priv, queryArgs, supplyArgs, passCheck)
251256
Expect(err).ToNot(HaveOccurred(), "unexpected result calling contract")
252257

253-
supply, err := decodeSupplyOfResult(ethRes.Ret)
258+
var ret bank2.SupplyOfReturn
259+
_, err = ret.Decode(ethRes.Ret)
254260
Expect(err).ToNot(HaveOccurred(), "failed to unpack balances")
255261

256-
Expect(supply.String()).To(Equal(cosmosEVMTotalSupply.String()))
262+
Expect(ret.TotalSupply.String()).To(Equal(cosmosEVMTotalSupply.String()))
257263
})
258264

259265
It("should return the supply of XMPL", func() {
260266
queryArgs, supplyArgs := getTxAndCallArgs(directCall, contractData, bank2.SupplyOfMethod, is.xmplAddr)
261267
_, ethRes, err := is.factory.CallContractAndCheckLogs(sender.Priv, queryArgs, supplyArgs, passCheck)
262268
Expect(err).ToNot(HaveOccurred(), "unexpected result calling contract")
263269

264-
supply, err := decodeSupplyOfResult(ethRes.Ret)
270+
var ret bank2.SupplyOfReturn
271+
_, err = ret.Decode(ethRes.Ret)
265272
Expect(err).ToNot(HaveOccurred(), "failed to unpack balances")
266273

267-
Expect(supply.String()).To(Equal(xmplTotalSupply.String()))
274+
Expect(ret.TotalSupply.String()).To(Equal(xmplTotalSupply.String()))
268275
})
269276

270277
It("should return a supply of 0 for a non existing token", func() {
271278
queryArgs, supplyArgs := getTxAndCallArgs(directCall, contractData, bank2.SupplyOfMethod, utiltx.GenerateAddress())
272279
_, ethRes, err := is.factory.CallContractAndCheckLogs(sender.Priv, queryArgs, supplyArgs, passCheck)
273280
Expect(err).ToNot(HaveOccurred(), "unexpected result calling contract")
274281

275-
supply, err := decodeSupplyOfResult(ethRes.Ret)
282+
var ret bank2.SupplyOfReturn
283+
_, err = ret.Decode(ethRes.Ret)
276284
Expect(err).ToNot(HaveOccurred(), "failed to unpack balances")
277285

278-
Expect(supply.Int64()).To(Equal(big.NewInt(0).Int64()))
286+
Expect(ret.TotalSupply.Int64()).To(Equal(big.NewInt(0).Int64()))
279287
})
280288

281289
It("should consume the correct amount of gas", func() {
@@ -308,14 +316,15 @@ func TestIntegrationSuite(t *testing.T, create network.CreateEvmApp, options ...
308316
_, ethRes, err := is.factory.CallContractAndCheckLogs(sender.Priv, queryArgs, balancesArgs, passCheck)
309317
Expect(err).ToNot(HaveOccurred(), "unexpected result calling contract")
310318

311-
balances, err := decodeBalancesResult(ethRes.Ret)
319+
var ret bank2.BalancesReturn
320+
_, err = ret.Decode(ethRes.Ret)
312321
Expect(err).ToNot(HaveOccurred(), "failed to unpack balances")
313322

314323
balanceAfter, err := is.grpcHandler.GetBalanceFromBank(receiver.Bytes(), is.tokenDenom)
315324
Expect(err).ToNot(HaveOccurred(), "failed to get balance")
316325

317-
Expect(math.NewInt(balances[0].Amount.Int64())).To(Equal(balanceAfter.Balance.Amount))
318-
Expect(*balances[0].Amount).To(Equal(*amount))
326+
Expect(math.NewInt(ret.Balances[0].Amount.Int64())).To(Equal(balanceAfter.Balance.Amount))
327+
Expect(*ret.Balances[0].Amount).To(Equal(*amount))
319328
})
320329

321330
It("should return a single token balance", func() {
@@ -330,25 +339,27 @@ func TestIntegrationSuite(t *testing.T, create network.CreateEvmApp, options ...
330339
_, ethRes, err := is.factory.CallContractAndCheckLogs(sender.Priv, queryArgs, balancesArgs, passCheck)
331340
Expect(err).ToNot(HaveOccurred(), "unexpected result calling contract")
332341

333-
balances, err := decodeBalancesResult(ethRes.Ret)
342+
var ret bank2.BalancesReturn
343+
_, err = ret.Decode(ethRes.Ret)
334344
Expect(err).ToNot(HaveOccurred(), "failed to unpack balances")
335345

336346
balanceAfter, err := is.grpcHandler.GetBalanceFromBank(receiver.Bytes(), is.network.GetBaseDenom())
337347
Expect(err).ToNot(HaveOccurred(), "failed to get balance")
338348

339-
Expect(math.NewInt(balances[0].Amount.Int64())).To(Equal(balanceAfter.Balance.Amount))
340-
Expect(*balances[0].Amount).To(Equal(*amount))
349+
Expect(math.NewInt(ret.Balances[0].Amount.Int64())).To(Equal(balanceAfter.Balance.Amount))
350+
Expect(*ret.Balances[0].Amount).To(Equal(*amount))
341351
})
342352

343353
It("should return no balance for new account", func() {
344354
queryArgs, balancesArgs := getTxAndCallArgs(contractCall, contractData, BalancesFunction, utiltx.GenerateAddress())
345355
_, ethRes, err := is.factory.CallContractAndCheckLogs(sender.Priv, queryArgs, balancesArgs, passCheck)
346356
Expect(err).ToNot(HaveOccurred(), "unexpected result calling contract")
347357

348-
balances, err := decodeBalancesResult(ethRes.Ret)
358+
var ret bank2.BalancesReturn
359+
_, err = ret.Decode(ethRes.Ret)
349360
Expect(err).ToNot(HaveOccurred(), "failed to unpack balances")
350361

351-
Expect(balances).To(BeEmpty())
362+
Expect(ret.Balances).To(BeEmpty())
352363
})
353364

354365
It("should consume the correct amount of gas", func() {
@@ -359,10 +370,11 @@ func TestIntegrationSuite(t *testing.T, create network.CreateEvmApp, options ...
359370
ethRes, err := evmtypes.DecodeTxResponse(res.Data)
360371
Expect(err).ToNot(HaveOccurred(), "failed to decode tx response")
361372

362-
balances, err := decodeBalancesResult(ethRes.Ret)
373+
var ret bank2.BalancesReturn
374+
_, err = ret.Decode(ethRes.Ret)
363375
Expect(err).ToNot(HaveOccurred(), "failed to unpack balances")
364376

365-
gasUsed := Max(bank2.GasBalances, len(balances)*bank2.GasBalances)
377+
gasUsed := Max(bank2.GasBalances, len(ret.Balances)*bank2.GasBalances)
366378
// Here increasing the GasBalanceOf will increase the use of gas so they will never be equal
367379
Expect(gasUsed).To(BeNumerically("<=", ethRes.GasUsed))
368380
})
@@ -374,11 +386,12 @@ func TestIntegrationSuite(t *testing.T, create network.CreateEvmApp, options ...
374386
_, ethRes, err := is.factory.CallContractAndCheckLogs(sender.Priv, queryArgs, supplyArgs, passCheck)
375387
Expect(err).ToNot(HaveOccurred(), "unexpected result calling contract")
376388

377-
balances, err := decodeTotalSupplyResult(ethRes.Ret)
389+
var ret bank2.TotalSupplyReturn
390+
_, err = ret.Decode(ethRes.Ret)
378391
Expect(err).ToNot(HaveOccurred(), "failed to unpack balances")
379392

380-
Expect(balances[0].Amount.String()).To(Equal(cosmosEVMTotalSupply.String()))
381-
Expect(balances[1].Amount.String()).To(Equal(xmplTotalSupply.String()))
393+
Expect(ret.TotalSupply[0].Amount.String()).To(Equal(cosmosEVMTotalSupply.String()))
394+
Expect(ret.TotalSupply[1].Amount.String()).To(Equal(xmplTotalSupply.String()))
382395
})
383396
})
384397

@@ -388,32 +401,35 @@ func TestIntegrationSuite(t *testing.T, create network.CreateEvmApp, options ...
388401
_, ethRes, err := is.factory.CallContractAndCheckLogs(sender.Priv, queryArgs, supplyArgs, passCheck)
389402
Expect(err).ToNot(HaveOccurred(), "unexpected result calling contract")
390403

391-
supply, err := decodeSupplyOfResult(ethRes.Ret)
404+
var ret bank2.SupplyOfReturn
405+
_, err = ret.Decode(ethRes.Ret)
392406
Expect(err).ToNot(HaveOccurred(), "failed to unpack balances")
393407

394-
Expect(supply.String()).To(Equal(cosmosEVMTotalSupply.String()))
408+
Expect(ret.TotalSupply.String()).To(Equal(cosmosEVMTotalSupply.String()))
395409
})
396410

397411
It("should return the supply of XMPL", func() {
398412
queryArgs, supplyArgs := getTxAndCallArgs(contractCall, contractData, SupplyOfFunction, is.xmplAddr)
399413
_, ethRes, err := is.factory.CallContractAndCheckLogs(sender.Priv, queryArgs, supplyArgs, passCheck)
400414
Expect(err).ToNot(HaveOccurred(), "unexpected result calling contract")
401415

402-
supply, err := decodeSupplyOfResult(ethRes.Ret)
416+
var ret bank2.SupplyOfReturn
417+
_, err = ret.Decode(ethRes.Ret)
403418
Expect(err).ToNot(HaveOccurred(), "failed to unpack balances")
404419

405-
Expect(supply.String()).To(Equal(xmplTotalSupply.String()))
420+
Expect(ret.TotalSupply.String()).To(Equal(xmplTotalSupply.String()))
406421
})
407422

408423
It("should return a supply of 0 for a non existing token", func() {
409424
queryArgs, supplyArgs := getTxAndCallArgs(contractCall, contractData, SupplyOfFunction, utiltx.GenerateAddress())
410425
_, ethRes, err := is.factory.CallContractAndCheckLogs(sender.Priv, queryArgs, supplyArgs, passCheck)
411426
Expect(err).ToNot(HaveOccurred(), "unexpected result calling contract")
412427

413-
supply, err := decodeSupplyOfResult(ethRes.Ret)
428+
var ret bank2.SupplyOfReturn
429+
_, err = ret.Decode(ethRes.Ret)
414430
Expect(err).ToNot(HaveOccurred(), "failed to unpack balances")
415431

416-
Expect(supply.Int64()).To(Equal(big.NewInt(0).Int64()))
432+
Expect(ret.TotalSupply.Int64()).To(Equal(big.NewInt(0).Int64()))
417433
})
418434

419435
It("should consume the correct amount of gas", func() {

tests/integration/precompiles/bank/test_utils.go

Lines changed: 0 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package bank
22

33
import (
44
"fmt"
5-
"math/big"
65

76
"github.com/ethereum/go-ethereum/accounts/abi"
87
"github.com/ethereum/go-ethereum/common"
@@ -126,36 +125,6 @@ func getTxAndCallArgs(
126125
return txArgs, callArgs
127126
}
128127

129-
// decodeBalancesResult decodes the result from a balances query
130-
func decodeBalancesResult(data []byte) ([]bank.Balance, error) {
131-
var result bank.BalancesReturn
132-
_, err := result.Decode(data)
133-
if err != nil {
134-
return nil, err
135-
}
136-
return result.Balances, nil
137-
}
138-
139-
// decodeTotalSupplyResult decodes the result from a totalSupply query
140-
func decodeTotalSupplyResult(data []byte) ([]bank.Balance, error) {
141-
var result bank.TotalSupplyReturn
142-
_, err := result.Decode(data)
143-
if err != nil {
144-
return nil, err
145-
}
146-
return result.TotalSupply, nil
147-
}
148-
149-
// decodeSupplyOfResult decodes the result from a supplyOf query
150-
func decodeSupplyOfResult(data []byte) (*big.Int, error) {
151-
var result bank.SupplyOfReturn
152-
_, err := result.Decode(data)
153-
if err != nil {
154-
return nil, err
155-
}
156-
return result.TotalSupply, nil
157-
}
158-
159128
func Max(x, y int) int {
160129
if x > y {
161130
return x

0 commit comments

Comments
 (0)