Skip to content

Commit

Permalink
refactor: ✅ eth: add simulator test
Browse files Browse the repository at this point in the history
Signed-off-by: thanhpp <[email protected]>
  • Loading branch information
thanhpp committed Apr 5, 2024
1 parent 6730cf7 commit ea799b9
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 1 deletion.
2 changes: 1 addition & 1 deletion pkg/eth/simulator.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ func NewSimulator(c *rpc.Client) *Simulator {
}

func (s *Simulator) EstimateGasWithOverrides(
ctx context.Context, msg ethereum.CallMsg, block *big.Int, blockNumber *big.Int,
ctx context.Context, msg ethereum.CallMsg, blockNumber *big.Int,
overrides *map[common.Address]gethclient.OverrideAccount,
) (uint64, error) {
var hex hexutil.Uint64
Expand Down
43 changes: 43 additions & 0 deletions pkg/eth/simulator_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package eth_test

import (
"context"
"testing"

"github.com/KyberNetwork/tradinglib/pkg/convert"
"github.com/KyberNetwork/tradinglib/pkg/eth"
"github.com/ethereum/go-ethereum"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/ethclient/gethclient"
"github.com/ethereum/go-ethereum/rpc"
"github.com/stretchr/testify/require"
)

func TestEstimateGasWithOverrides(t *testing.T) {
t.Skip()

var (
url = "https://ethereum.kyberengineering.io"
wallet = common.HexToAddress("0x72CE0F4a9dbB974D3B1a9bF7ca857fD381260e97")
ethValue, _ = convert.FloatToWei(10, 18)
)

c, err := rpc.Dial(url)
require.NoError(t, err)

s := eth.NewSimulator(c)

gasUnit, err := s.EstimateGasWithOverrides(context.Background(), ethereum.CallMsg{
From: wallet,
To: &wallet,
Value: ethValue,
}, nil, &map[common.Address]gethclient.OverrideAccount{
wallet: {
Code: []byte("0x6"),
Balance: ethValue,
},
},
)
require.NoError(t, err)
t.Log(gasUnit)
}

0 comments on commit ea799b9

Please sign in to comment.