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
This commit is contained in:
ramil 2021-04-23 12:46:35 +03:00
parent 1141f3909c
commit 97d8c4dc86
4 changed files with 57 additions and 2 deletions

16
chain.json Normal file
View File

@ -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
}
}

View File

@ -54,12 +54,17 @@ services:
IPLD_POSTGRAPHILEPATH: http://graphql:5000 IPLD_POSTGRAPHILEPATH: http://graphql:5000
ETH_SERVER_HTTPPATH: 0.0.0.0:8081 ETH_SERVER_HTTPPATH: 0.0.0.0:8081
VDB_COMMAND: "serve" VDB_COMMAND: "serve"
ETH_CHAIN_CONFIG: "/tmp/chain.json"
DATABASE_NAME: "vulcanize_public" DATABASE_NAME: "vulcanize_public"
DATABASE_HOSTNAME: "db" DATABASE_HOSTNAME: "db"
DATABASE_PORT: 5432 DATABASE_PORT: 5432
DATABASE_USER: "vdbm" DATABASE_USER: "vdbm"
DATABASE_PASSWORD: "password" DATABASE_PASSWORD: "password"
ETH_CHAIN_ID: 4 ETH_CHAIN_ID: 4
volumes:
- type: bind
source: ./chain.json
target: /tmp/chain.json
ports: ports:
- "127.0.0.1:8081:8081" - "127.0.0.1:8081:8081"

View File

@ -644,6 +644,10 @@ func (pea *PublicEthAPI) GetBalance(ctx context.Context, address common.Address,
return res, nil return res, nil
} }
} }
if err == sql.ErrNoRows {
return (*hexutil.Big)(big.NewInt(0)), nil
}
return nil, err return nil, err
} }
@ -680,6 +684,9 @@ func (pea *PublicEthAPI) GetStorageAt(ctx context.Context, address common.Addres
return res, nil return res, nil
} }
} }
if err == sql.ErrNoRows {
return make([]byte, 32), nil
}
return nil, err return nil, err
} }

View File

@ -32,8 +32,10 @@ var _ = Describe("Integration test", func() {
var contract *integration.ContractDeployed var contract *integration.ContractDeployed
var erc20TotalSupply *big.Int var erc20TotalSupply *big.Int
var tx *integration.Tx
var bigIntResult bool var bigIntResult bool
var contractErr error var contractErr error
var txErr error
sleepInterval := 2 * time.Second sleepInterval := 2 * time.Second
Describe("get Block", func() { Describe("get Block", func() {
@ -196,7 +198,7 @@ var _ = Describe("Integration test", func() {
}) })
}) })
Describe("", func() { Describe("CodeAt", func() {
BeforeEach(func() { BeforeEach(func() {
contract, contractErr = integration.DeployContract() contract, contractErr = integration.DeployContract()
time.Sleep(sleepInterval) time.Sleep(sleepInterval)
@ -244,7 +246,10 @@ var _ = Describe("Integration test", func() {
Describe("Get balance", func() { Describe("Get balance", func() {
address := "0x1111111111111111111111111111111111111112" 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() { It("gets balance for an account with eth without block number", func() {
Expect(txErr).ToNot(HaveOccurred()) 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))) ipldBalance, err := ipldClient.BalanceAt(ctx, common.HexToAddress(address), big.NewInt(int64(tx.BlockNumber-1)))
Expect(err).ToNot(HaveOccurred()) 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)) Expect(gethBalance).To(Equal(ipldBalance))
}) })
}) })
@ -323,6 +339,17 @@ var _ = Describe("Integration test", func() {
Expect(err).ToNot(HaveOccurred()) Expect(err).ToNot(HaveOccurred())
Expect(gethStorage).To(Equal(ipldStorage)) 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() { Describe("eth call", func() {