diff --git a/chain.json b/chain.json new file mode 100644 index 000000000..02d95d498 --- /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 01fbda21a..fed35b800 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 1e45b308e..b70fbca63 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 b55adf1b4..448d02e4c 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() {