Skip to content

Commit

Permalink
fix test bug
Browse files Browse the repository at this point in the history
  • Loading branch information
frankcrypto committed Sep 20, 2024
1 parent d96cf8d commit fdc0509
Showing 1 changed file with 7 additions and 11 deletions.
18 changes: 7 additions & 11 deletions test/token/evm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,14 @@ func TestCallErc20Contract(t *testing.T) {
lockTime := int64(20)
spendAmt := types.Amount{Value: 14000 * types.AtomsPerCoin, Id: types.MEERA}
txid := testutils.SendSelfMockNode(t, h, spendAmt, &lockTime)
testutils.GenerateBlocks(t, h, 1)
testutils.GenerateBlocksWaitForTxs(t, h, []string{txid.String()})
fee := int64(2200)
txH := testutils.SendExportTxMockNode(t, h, txid.String(), 0, spendAmt.Value-fee)
if txH == nil {
t.Fatalf("createExportRawTx failed:%v", err)
}
log.Println("send tx", txH.String())
testutils.GenerateBlocks(t, h, 1)
testutils.GenerateBlocksWaitForTxs(t, h, []string{txH.String()})
acc := h.GetWalletManager().GetAccountByIdx(0)
if err != nil {
t.Fatalf("GetAcctInfo failed:%v", err)
Expand Down Expand Up @@ -149,7 +149,6 @@ func TestCallErc20Contract(t *testing.T) {
log.Println(i, "address", target.String(), "balance", ba)
assert.Equal(t, ba, big.NewInt(toAmount).Mul(big.NewInt(toAmount), big.NewInt(1e18)))
}
testutils.GenerateBlocks(t, h, 1)
// check transferFrom

// not approve
Expand All @@ -160,23 +159,20 @@ func TestCallErc20Contract(t *testing.T) {

tx1, err := tokenCall.TransferFrom(authCaller1, acc.EvmAcct.Address, h.GetWalletManager().GetAccountByIdx(1).EvmAcct.Address, big.NewInt(toAmount).Mul(big.NewInt(toAmount), big.NewInt(1e18)))
if err == nil {
testutils.GenerateBlocksWaitForTxs(t, h, []string{tx1.Hash().String()})
testutils.GenerateBlocks(t, h, 1)
// check the transaction is ok or not
txD2, err := h.GetEvmClient().TransactionReceipt(context.Background(), tx1.Hash())
if err != nil {
t.Fatal(err)
}
if txD2.Status == uint64(0x1) {
if err == nil && txD2.Status == uint64(0x1) {
t.Fatal("Token Bug,TransferFrom without approve")
}
}
log.Println(err)

// approve
_, err = tokenCall.Approve(authCaller, h.GetWalletManager().GetAccountByIdx(1).EvmAcct.Address, big.NewInt(toAmount).Mul(big.NewInt(toAmount), big.NewInt(1e18)))
txAp, err := tokenCall.Approve(authCaller, h.GetWalletManager().GetAccountByIdx(1).EvmAcct.Address, big.NewInt(toAmount).Mul(big.NewInt(toAmount), big.NewInt(1e18)))
if err != nil {
t.Fatal("approve error", err)
}
testutils.GenerateBlocks(t, h, 1)
testutils.GenerateBlocksWaitForTxs(t, h, []string{txAp.Hash().String()})
_, err = tokenCall.TransferFrom(authCaller1, acc.EvmAcct.Address, h.GetWalletManager().GetAccountByIdx(1).EvmAcct.Address, big.NewInt(toAmount).Mul(big.NewInt(toAmount), big.NewInt(1e18)))
if err != nil {
t.Fatal("TransferFrom error", err)
Expand Down

0 comments on commit fdc0509

Please sign in to comment.