-
Notifications
You must be signed in to change notification settings - Fork 37
/
test_utils.go
52 lines (41 loc) · 1.17 KB
/
test_utils.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
package test_env
import (
"context"
"fmt"
"math/big"
"github.com/ethereum/go-ethereum"
"github.com/ethereum/go-ethereum/common"
"github.com/smartcontractkit/chainlink-testing-framework/blockchain"
)
func sendAndCompareBalances(ctx context.Context, c blockchain.EVMClient, address common.Address) error {
balanceBefore, err := c.BalanceAt(ctx, address)
if err != nil {
return err
}
toSendEth := big.NewFloat(1)
exp := new(big.Int).Exp(big.NewInt(10), big.NewInt(18), nil)
toSendEthInt := new(big.Int)
_, _ = toSendEth.Int(toSendEthInt)
sentInWei := new(big.Int).Mul(toSendEthInt, exp)
gasEstimations, err := c.EstimateGas(ethereum.CallMsg{
From: common.HexToAddress(c.GetDefaultWallet().Address()),
To: &address,
Value: sentInWei,
})
if err != nil {
return err
}
err = c.Fund(address.Hex(), toSendEth, gasEstimations)
if err != nil {
return err
}
balanceAfter, err := c.BalanceAt(ctx, address)
if err != nil {
return err
}
expected := big.NewInt(0).Add(balanceBefore, sentInWei)
if expected.Cmp(balanceAfter) != 0 {
return fmt.Errorf("balance is incorrect. Expected %s, got %s", expected.String(), balanceAfter.String())
}
return nil
}