Skip to content

Commit

Permalink
integration tests: fix issue with eth_call (pass chain config via jso…
Browse files Browse the repository at this point in the history
…n file to match geth chain config)

added additional test case: gets balance for a non-existing account without block number
  • Loading branch information
ramilexe committed Apr 23, 2021
1 parent 1141f39 commit 97d8c4d
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 2 deletions.
16 changes: 16 additions & 0 deletions chain.json
Original file line number Diff line number Diff line change
@@ -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
}
}
5 changes: 5 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down
7 changes: 7 additions & 0 deletions pkg/eth/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down Expand Up @@ -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
}

Expand Down
31 changes: 29 additions & 2 deletions test/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -196,7 +198,7 @@ var _ = Describe("Integration test", func() {
})
})

Describe("", func() {
Describe("CodeAt", func() {
BeforeEach(func() {
contract, contractErr = integration.DeployContract()
time.Sleep(sleepInterval)
Expand Down Expand Up @@ -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())
Expand Down Expand Up @@ -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))
})
})
Expand Down Expand Up @@ -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() {
Expand Down

0 comments on commit 97d8c4d

Please sign in to comment.