From 97d8c4dc8624a679f4ed069649204c02e8938f37 Mon Sep 17 00:00:00 2001 From: ramil Date: Fri, 23 Apr 2021 12:46:35 +0300 Subject: [PATCH] integration tests: fix issue with eth_call (pass chain config via json file to match geth chain config) added additional test case: gets balance for a non-existing account without block number --- chain.json | 16 ++++++++++++++++ docker-compose.yml | 5 +++++ pkg/eth/api.go | 7 +++++++ test/integration_test.go | 31 +++++++++++++++++++++++++++++-- 4 files changed, 57 insertions(+), 2 deletions(-) create mode 100644 chain.json diff --git a/chain.json b/chain.json new file mode 100644 index 00000000..02d95d49 --- /dev/null +++ b/chain.json @@ -0,0 +1,16 @@ +{ + "chainId": 4, + "homesteadBlock": 1, + "eip150Block": 2, + "eip150Hash": "0x9b095b36c15eaf13044373aef8ee0bd3a382a5abb92e402afa44b8249c3a90e9", + "eip155Block": 3, + "eip158Block": 3, + "byzantiumBlock": 3, + "constantinopleBlock": 3, + "petersburgBlock": 3, + "istanbulBlock": 3, + "clique": { + "period": 15, + "epoch": 30000 + } +} \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml index 01fbda21..fed35b80 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -54,12 +54,17 @@ services: IPLD_POSTGRAPHILEPATH: http://graphql:5000 ETH_SERVER_HTTPPATH: 0.0.0.0:8081 VDB_COMMAND: "serve" + ETH_CHAIN_CONFIG: "/tmp/chain.json" DATABASE_NAME: "vulcanize_public" DATABASE_HOSTNAME: "db" DATABASE_PORT: 5432 DATABASE_USER: "vdbm" DATABASE_PASSWORD: "password" ETH_CHAIN_ID: 4 + volumes: + - type: bind + source: ./chain.json + target: /tmp/chain.json ports: - "127.0.0.1:8081:8081" diff --git a/pkg/eth/api.go b/pkg/eth/api.go index 1e45b308..b70fbca6 100644 --- a/pkg/eth/api.go +++ b/pkg/eth/api.go @@ -644,6 +644,10 @@ func (pea *PublicEthAPI) GetBalance(ctx context.Context, address common.Address, return res, nil } } + if err == sql.ErrNoRows { + return (*hexutil.Big)(big.NewInt(0)), nil + } + return nil, err } @@ -680,6 +684,9 @@ func (pea *PublicEthAPI) GetStorageAt(ctx context.Context, address common.Addres return res, nil } } + if err == sql.ErrNoRows { + return make([]byte, 32), nil + } return nil, err } diff --git a/test/integration_test.go b/test/integration_test.go index b55adf1b..448d02e4 100644 --- a/test/integration_test.go +++ b/test/integration_test.go @@ -32,8 +32,10 @@ var _ = Describe("Integration test", func() { var contract *integration.ContractDeployed var erc20TotalSupply *big.Int + var tx *integration.Tx var bigIntResult bool var contractErr error + var txErr error sleepInterval := 2 * time.Second Describe("get Block", func() { @@ -196,7 +198,7 @@ var _ = Describe("Integration test", func() { }) }) - Describe("", func() { + Describe("CodeAt", func() { BeforeEach(func() { contract, contractErr = integration.DeployContract() time.Sleep(sleepInterval) @@ -244,7 +246,10 @@ var _ = Describe("Integration test", func() { Describe("Get balance", func() { address := "0x1111111111111111111111111111111111111112" - tx, txErr := integration.SendEth(address, "0.01") + BeforeEach(func() { + tx, txErr = integration.SendEth(address, "0.01") + time.Sleep(sleepInterval) + }) It("gets balance for an account with eth without block number", func() { Expect(txErr).ToNot(HaveOccurred()) @@ -277,6 +282,17 @@ var _ = Describe("Integration test", func() { ipldBalance, err := ipldClient.BalanceAt(ctx, common.HexToAddress(address), big.NewInt(int64(tx.BlockNumber-1))) Expect(err).ToNot(HaveOccurred()) + Expect(gethBalance).To(Equal(ipldBalance)) + }) + It("gets balance for a non-existing account without block number", func() { + Expect(txErr).ToNot(HaveOccurred()) + + gethBalance, err := gethClient.BalanceAt(ctx, common.HexToAddress(nonExistingAddress), nil) + Expect(err).ToNot(HaveOccurred()) + + ipldBalance, err := ipldClient.BalanceAt(ctx, common.HexToAddress(nonExistingAddress), nil) + Expect(err).ToNot(HaveOccurred()) + Expect(gethBalance).To(Equal(ipldBalance)) }) }) @@ -323,6 +339,17 @@ var _ = Describe("Integration test", func() { Expect(err).ToNot(HaveOccurred()) Expect(gethStorage).To(Equal(ipldStorage)) }) + It("gets storage for non-existing account", func() { + totalSupplyIndex := "0x2" + + gethStorage, err := gethClient.StorageAt(ctx, common.HexToAddress(nonExistingAddress), common.HexToHash(totalSupplyIndex), big.NewInt(int64(contract.BlockNumber))) + Expect(err).ToNot(HaveOccurred()) + + ipldStorage, err := ipldClient.StorageAt(ctx, common.HexToAddress(nonExistingAddress), common.HexToHash(totalSupplyIndex), big.NewInt(int64(contract.BlockNumber))) + + Expect(err).ToNot(HaveOccurred()) + Expect(gethStorage).To(Equal(ipldStorage)) + }) }) Describe("eth call", func() {