From ea799b9f4d54f179ef69e0af13bd8e6df7666eaf Mon Sep 17 00:00:00 2001 From: thanhpp Date: Fri, 5 Apr 2024 16:42:55 +0700 Subject: [PATCH] =?UTF-8?q?refactor:=20=E2=9C=85=20eth:=20add=20simulator?= =?UTF-8?q?=20test?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: thanhpp --- pkg/eth/simulator.go | 2 +- pkg/eth/simulator_test.go | 43 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 44 insertions(+), 1 deletion(-) create mode 100644 pkg/eth/simulator_test.go diff --git a/pkg/eth/simulator.go b/pkg/eth/simulator.go index 417da9f..14c86b2 100644 --- a/pkg/eth/simulator.go +++ b/pkg/eth/simulator.go @@ -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 diff --git a/pkg/eth/simulator_test.go b/pkg/eth/simulator_test.go new file mode 100644 index 0000000..138193a --- /dev/null +++ b/pkg/eth/simulator_test.go @@ -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) +}