diff --git a/pkg/eth/api.go b/pkg/eth/api.go index d44dd0ef..b701d089 100644 --- a/pkg/eth/api.go +++ b/pkg/eth/api.go @@ -714,7 +714,7 @@ func (pea *PublicEthAPI) GetStorageAt(ctx context.Context, address common.Addres } } if err == sql.ErrNoRows { - return hexutil.Bytes{}, errors.New("header not found") + return make([]byte, 32), nil } return nil, err } diff --git a/pkg/eth/api_test.go b/pkg/eth/api_test.go index b97c6c7d..f4e8ad47 100644 --- a/pkg/eth/api_test.go +++ b/pkg/eth/api_test.go @@ -333,7 +333,7 @@ var _ = Describe("API", func() { Expect(err).ToNot(HaveOccurred()) Expect(uncle2).To(Equal(expectedUncle2)) }) - It("Returns `nil` if an block for blocknumber cannot be found", func() { + It("Returns `nil` if an block for block number cannot be found", func() { block, err := api.GetUncleByBlockNumberAndIndex(ctx, wrongNumber, 0) Expect(err).ToNot(HaveOccurred()) Expect(block).To(BeNil()) diff --git a/pkg/eth/backend.go b/pkg/eth/backend.go index 77895de4..07e4c709 100644 --- a/pkg/eth/backend.go +++ b/pkg/eth/backend.go @@ -598,8 +598,8 @@ func (b *Backend) GetAccountByNumber(ctx context.Context, address common.Address return nil, errPendingBlockNumber } hash, err := b.GetCanonicalHash(uint64(number)) - if err == sql.ErrNoRows || hash == (common.Hash{}) { - return nil, fmt.Errorf("no canoncial block hash found for provided height (%d)", number) + if err == sql.ErrNoRows { + return nil, fmt.Errorf("header not found") } else if err != nil { return nil, err } diff --git a/pkg/eth/eth_state_test.go b/pkg/eth/eth_state_test.go index cc701eea..e9a45e43 100644 --- a/pkg/eth/eth_state_test.go +++ b/pkg/eth/eth_state_test.go @@ -79,7 +79,7 @@ var _ = Describe("eth state reading tests", func() { backend, err = eth.NewEthBackend(db, ð.Config{ ChainConfig: chainConfig, VmConfig: vm.Config{}, - RPCGasCap: big.NewInt(10000000000), + RPCGasCap: big.NewInt(10000000000), // Max gas capacity for a rpc call. }) Expect(err).ToNot(HaveOccurred()) api = eth.NewPublicEthAPI(backend, nil, false) @@ -456,19 +456,19 @@ var _ = Describe("eth state reading tests", func() { }) Describe("eth_getStorageAt", func() { - It("Throws an error if it tries to access a contract which does not exist", func() { - _, err := api.GetStorageAt(ctx, test_helpers.ContractAddr, test_helpers.ContractSlotKeyHash.Hex(), rpc.BlockNumberOrHashWithNumber(0)) - Expect(err).To(HaveOccurred()) - Expect(err.Error()).To(ContainSubstring("header not found")) + It("Returns empty slice if it tries to access a contract which does not exist", func() { + storage, err := api.GetStorageAt(ctx, test_helpers.ContractAddr, test_helpers.ContractSlotKeyHash.Hex(), rpc.BlockNumberOrHashWithNumber(0)) + Expect(err).NotTo(HaveOccurred()) + Expect(storage).To(Equal(hexutil.Bytes(make([]byte, 32)))) - _, err = api.GetStorageAt(ctx, test_helpers.ContractAddr, test_helpers.ContractSlotKeyHash.Hex(), rpc.BlockNumberOrHashWithNumber(1)) - Expect(err).To(HaveOccurred()) - Expect(err.Error()).To(ContainSubstring("header not found")) + storage, err = api.GetStorageAt(ctx, test_helpers.ContractAddr, test_helpers.ContractSlotKeyHash.Hex(), rpc.BlockNumberOrHashWithNumber(1)) + Expect(err).NotTo(HaveOccurred()) + Expect(storage).To(Equal(hexutil.Bytes(make([]byte, 32)))) }) - It("Throws an error if it tries to access a contract slot which does not exist", func() { - _, err := api.GetStorageAt(ctx, test_helpers.ContractAddr, randomHash.Hex(), rpc.BlockNumberOrHashWithNumber(2)) - Expect(err).To(HaveOccurred()) - Expect(err.Error()).To(ContainSubstring("header not found")) + It("Returns empty slice if it tries to access a contract slot which does not exist", func() { + storage, err := api.GetStorageAt(ctx, test_helpers.ContractAddr, randomHash.Hex(), rpc.BlockNumberOrHashWithNumber(2)) + Expect(err).NotTo(HaveOccurred()) + Expect(storage).To(Equal(hexutil.Bytes(make([]byte, 32)))) }) It("Retrieves the storage value at the provided contract address and storage leaf key at the block with the provided hash or number", func() { // After deployment diff --git a/test/integration_test.go b/test/integration_test.go index 76a8e993..af93054a 100644 --- a/test/integration_test.go +++ b/test/integration_test.go @@ -291,6 +291,17 @@ var _ = Describe("Integration test", func() { ipldBalance, err := ipldClient.BalanceAt(ctx, common.HexToAddress(nonExistingAddress), nil) Expect(err).ToNot(HaveOccurred()) + Expect(gethBalance).To(Equal(ipldBalance)) + }) + It("gets balance for an non-existing block number", func() { + Expect(txErr).ToNot(HaveOccurred()) + + gethBalance, err := gethClient.BalanceAt(ctx, common.HexToAddress(address), big.NewInt(int64(tx.BlockNumber+3))) + Expect(err).To(MatchError("header not found")) + + ipldBalance, err := ipldClient.BalanceAt(ctx, common.HexToAddress(nonExistingAddress), big.NewInt(int64(tx.BlockNumber+3))) + Expect(err).To(MatchError("header not found")) + Expect(gethBalance).To(Equal(ipldBalance)) }) })