2021-12-29 21:01:09 +00:00
|
|
|
package integration_test
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"math/big"
|
2023-04-14 06:26:46 +00:00
|
|
|
"math/rand"
|
2021-12-29 21:01:09 +00:00
|
|
|
|
|
|
|
"github.com/ethereum/go-ethereum"
|
|
|
|
"github.com/ethereum/go-ethereum/common"
|
2023-04-14 06:26:46 +00:00
|
|
|
. "github.com/onsi/ginkgo/v2"
|
2021-12-29 21:01:09 +00:00
|
|
|
. "github.com/onsi/gomega"
|
|
|
|
|
2023-05-26 06:12:01 +00:00
|
|
|
"github.com/cerc-io/ipld-eth-server/v5/integration"
|
2023-04-14 06:26:46 +00:00
|
|
|
"github.com/cerc-io/ipld-eth-server/v5/pkg/eth"
|
2021-12-29 21:01:09 +00:00
|
|
|
)
|
|
|
|
|
2023-04-14 06:26:46 +00:00
|
|
|
var _ = Describe("Direct proxy integration test", Label("proxy"), func() {
|
2021-12-29 21:01:09 +00:00
|
|
|
ctx := context.Background()
|
|
|
|
|
|
|
|
var contract *integration.ContractDeployed
|
|
|
|
var tx *integration.Tx
|
|
|
|
var contractErr error
|
|
|
|
var txErr error
|
2022-03-16 16:15:31 +00:00
|
|
|
|
2021-12-29 21:01:09 +00:00
|
|
|
Describe("get Block", func() {
|
|
|
|
BeforeEach(func() {
|
|
|
|
contract, contractErr = integration.DeployContract()
|
2023-04-14 06:26:46 +00:00
|
|
|
Expect(contractErr).ToNot(HaveOccurred())
|
2021-12-29 21:01:09 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
It("get not existing block by number", func() {
|
|
|
|
blockNum := contract.BlockNumber + 100
|
|
|
|
|
2023-04-14 06:26:46 +00:00
|
|
|
gethBlock, err := gethClient.BlockByNumber(ctx, big.NewInt(blockNum))
|
2021-12-29 21:01:09 +00:00
|
|
|
Expect(err).To(MatchError(ethereum.NotFound))
|
|
|
|
Expect(gethBlock).To(BeZero())
|
|
|
|
|
2023-04-14 06:26:46 +00:00
|
|
|
ipldBlock, err := ipldClient.BlockByNumber(ctx, big.NewInt(blockNum))
|
2021-12-29 21:01:09 +00:00
|
|
|
Expect(err).To(MatchError(ethereum.NotFound))
|
|
|
|
Expect(ipldBlock).To(BeZero())
|
|
|
|
})
|
|
|
|
|
|
|
|
It("get not existing block by hash", func() {
|
2023-04-14 06:26:46 +00:00
|
|
|
gethBlock, err := gethClient.BlockByHash(ctx, nonExistingBlockHash)
|
2021-12-29 21:01:09 +00:00
|
|
|
Expect(err).To(MatchError(ethereum.NotFound))
|
|
|
|
Expect(gethBlock).To(BeZero())
|
|
|
|
|
2023-04-14 06:26:46 +00:00
|
|
|
ipldBlock, err := ipldClient.BlockByHash(ctx, nonExistingBlockHash)
|
2021-12-29 21:01:09 +00:00
|
|
|
Expect(err).To(MatchError(ethereum.NotFound))
|
|
|
|
Expect(ipldBlock).To(BeZero())
|
|
|
|
})
|
|
|
|
|
|
|
|
It("get block by number", func() {
|
|
|
|
blockNum := contract.BlockNumber
|
|
|
|
|
2023-04-14 06:26:46 +00:00
|
|
|
_, err := gethClient.BlockByNumber(ctx, big.NewInt(blockNum))
|
2021-12-29 21:01:09 +00:00
|
|
|
Expect(err).ToNot(HaveOccurred())
|
|
|
|
|
2023-04-14 06:26:46 +00:00
|
|
|
_, err = ipldClient.BlockByNumber(ctx, big.NewInt(blockNum))
|
2021-12-29 21:01:09 +00:00
|
|
|
Expect(err).To(HaveOccurred())
|
|
|
|
})
|
|
|
|
|
|
|
|
It("get block by hash", func() {
|
2023-04-14 06:26:46 +00:00
|
|
|
_, err := gethClient.BlockByHash(ctx, contract.BlockHash)
|
2021-12-29 21:01:09 +00:00
|
|
|
Expect(err).ToNot(HaveOccurred())
|
|
|
|
|
2023-04-14 06:26:46 +00:00
|
|
|
_, err = ipldClient.BlockByHash(ctx, contract.BlockHash)
|
2021-12-29 21:01:09 +00:00
|
|
|
Expect(err).To(HaveOccurred())
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
Describe("Transaction", func() {
|
|
|
|
BeforeEach(func() {
|
|
|
|
contract, contractErr = integration.DeployContract()
|
2023-04-14 06:26:46 +00:00
|
|
|
Expect(contractErr).ToNot(HaveOccurred())
|
2021-12-29 21:01:09 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
It("Get tx by hash", func() {
|
2023-04-14 06:26:46 +00:00
|
|
|
_, _, err := gethClient.TransactionByHash(ctx, contract.TransactionHash)
|
2021-12-29 21:01:09 +00:00
|
|
|
Expect(err).ToNot(HaveOccurred())
|
|
|
|
|
2023-04-14 06:26:46 +00:00
|
|
|
_, _, err = ipldClient.TransactionByHash(ctx, contract.TransactionHash)
|
2021-12-29 21:01:09 +00:00
|
|
|
Expect(err).To(HaveOccurred())
|
2023-04-14 06:26:46 +00:00
|
|
|
Expect(err.Error()).To(ContainSubstring("not found"))
|
2021-12-29 21:01:09 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
It("Get tx by block hash and index", func() {
|
2023-04-14 06:26:46 +00:00
|
|
|
_, err := gethClient.TransactionInBlock(ctx, contract.BlockHash, 0)
|
2021-12-29 21:01:09 +00:00
|
|
|
Expect(err).ToNot(HaveOccurred())
|
|
|
|
|
2023-04-14 06:26:46 +00:00
|
|
|
_, err = ipldClient.TransactionInBlock(ctx, contract.BlockHash, 0)
|
2021-12-29 21:01:09 +00:00
|
|
|
Expect(err).To(HaveOccurred())
|
2023-04-14 06:26:46 +00:00
|
|
|
Expect(err.Error()).To(ContainSubstring("not found"))
|
2021-12-29 21:01:09 +00:00
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
Describe("Receipt", func() {
|
|
|
|
BeforeEach(func() {
|
|
|
|
contract, contractErr = integration.DeployContract()
|
2023-04-14 06:26:46 +00:00
|
|
|
Expect(contractErr).ToNot(HaveOccurred())
|
2021-12-29 21:01:09 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
It("Get tx receipt", func() {
|
2023-04-14 06:26:46 +00:00
|
|
|
_, err := gethClient.TransactionReceipt(ctx, contract.TransactionHash)
|
2021-12-29 21:01:09 +00:00
|
|
|
Expect(err).ToNot(HaveOccurred())
|
|
|
|
|
2023-04-14 06:26:46 +00:00
|
|
|
_, err = ipldClient.TransactionReceipt(ctx, contract.TransactionHash)
|
2021-12-29 21:01:09 +00:00
|
|
|
Expect(err).To(HaveOccurred())
|
2023-04-14 06:26:46 +00:00
|
|
|
Expect(err.Error()).To(ContainSubstring("not found"))
|
2021-12-29 21:01:09 +00:00
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
Describe("FilterLogs", func() {
|
|
|
|
BeforeEach(func() {
|
|
|
|
contract, contractErr = integration.DeployContract()
|
2023-04-14 06:26:46 +00:00
|
|
|
Expect(contractErr).ToNot(HaveOccurred())
|
2021-12-29 21:01:09 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
It("with blockhash", func() {
|
2023-04-14 06:26:46 +00:00
|
|
|
blockHash := contract.BlockHash
|
2021-12-29 21:01:09 +00:00
|
|
|
filterQuery := ethereum.FilterQuery{
|
|
|
|
//Addresses: addresses,
|
|
|
|
BlockHash: &blockHash,
|
|
|
|
Topics: [][]common.Hash{},
|
|
|
|
}
|
|
|
|
|
2021-12-30 02:29:59 +00:00
|
|
|
gethLogs, err := gethClient.FilterLogs(ctx, filterQuery)
|
2021-12-29 21:01:09 +00:00
|
|
|
Expect(err).ToNot(HaveOccurred())
|
|
|
|
|
2021-12-30 02:29:59 +00:00
|
|
|
ipldLogs, err := ipldClient.FilterLogs(ctx, filterQuery)
|
|
|
|
Expect(err).ToNot(HaveOccurred())
|
|
|
|
|
|
|
|
// not empty list
|
|
|
|
Expect(gethLogs).ToNot(BeEmpty())
|
|
|
|
// empty list
|
|
|
|
Expect(ipldLogs).To(BeEmpty())
|
2021-12-29 21:01:09 +00:00
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
Describe("CodeAt", func() {
|
|
|
|
BeforeEach(func() {
|
|
|
|
contract, contractErr = integration.DeployContract()
|
2023-04-14 06:26:46 +00:00
|
|
|
Expect(contractErr).ToNot(HaveOccurred())
|
2021-12-29 21:01:09 +00:00
|
|
|
})
|
|
|
|
|
2023-04-14 06:26:46 +00:00
|
|
|
It("gets code of deployed contract with block number", func() {
|
|
|
|
_, err := gethClient.CodeAt(ctx, contract.Address, big.NewInt(contract.BlockNumber))
|
|
|
|
Expect(err).ToNot(HaveOccurred())
|
2021-12-29 21:01:09 +00:00
|
|
|
|
2023-04-14 06:26:46 +00:00
|
|
|
ipldCode, err := ipldClient.CodeAt(ctx, contract.Address, big.NewInt(contract.BlockNumber))
|
|
|
|
Expect(err).ToNot(HaveOccurred())
|
|
|
|
Expect(ipldCode).To(BeEmpty())
|
|
|
|
})
|
|
|
|
It("gets code of contract that doesn't exist at this height", func() {
|
|
|
|
gethCode, err := gethClient.CodeAt(ctx, contract.Address, big.NewInt(contract.BlockNumber-1))
|
2021-12-29 21:01:09 +00:00
|
|
|
Expect(err).ToNot(HaveOccurred())
|
|
|
|
|
2023-04-14 06:26:46 +00:00
|
|
|
ipldCode, err := ipldClient.CodeAt(ctx, contract.Address, big.NewInt(contract.BlockNumber-1))
|
2021-12-29 21:01:09 +00:00
|
|
|
Expect(err).ToNot(HaveOccurred())
|
|
|
|
|
|
|
|
Expect(gethCode).To(BeEmpty())
|
|
|
|
Expect(gethCode).To(Equal(ipldCode))
|
|
|
|
})
|
|
|
|
|
2023-04-14 06:26:46 +00:00
|
|
|
It("gets code at non-existing address without block number", func() {
|
|
|
|
gethCode, err := gethClient.CodeAt(ctx, nonExistingAddress, nil)
|
2021-12-29 21:01:09 +00:00
|
|
|
Expect(err).ToNot(HaveOccurred())
|
|
|
|
|
2023-04-14 06:26:46 +00:00
|
|
|
ipldCode, err := ipldClient.CodeAt(ctx, nonExistingAddress, nil)
|
2021-12-29 21:01:09 +00:00
|
|
|
Expect(err).ToNot(HaveOccurred())
|
2023-04-14 06:26:46 +00:00
|
|
|
|
|
|
|
Expect(gethCode).To(BeEmpty())
|
|
|
|
Expect(gethCode).To(Equal(ipldCode))
|
2021-12-29 21:01:09 +00:00
|
|
|
})
|
2023-04-14 06:26:46 +00:00
|
|
|
It("gets code of deployed contract without block number", func() {
|
|
|
|
_, err := gethClient.CodeAt(ctx, contract.Address, nil)
|
2021-12-29 21:01:09 +00:00
|
|
|
Expect(err).ToNot(HaveOccurred())
|
|
|
|
|
2023-04-14 06:26:46 +00:00
|
|
|
ipldCode, err := ipldClient.CodeAt(ctx, contract.Address, nil)
|
2021-12-29 21:01:09 +00:00
|
|
|
Expect(err).ToNot(HaveOccurred())
|
2023-04-14 06:26:46 +00:00
|
|
|
Expect(ipldCode).To(BeEmpty())
|
2021-12-29 21:01:09 +00:00
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
Describe("Get balance", func() {
|
2023-04-14 06:26:46 +00:00
|
|
|
var newAddress common.Address
|
|
|
|
rand.Read(newAddress[:])
|
|
|
|
|
2021-12-29 21:01:09 +00:00
|
|
|
BeforeEach(func() {
|
2023-04-14 06:26:46 +00:00
|
|
|
tx, txErr = integration.SendEth(newAddress, "0.01")
|
|
|
|
Expect(txErr).ToNot(HaveOccurred())
|
2021-12-29 21:01:09 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
It("gets balance for an account with eth without block number", func() {
|
2023-04-14 06:26:46 +00:00
|
|
|
gethBalance, err := gethClient.BalanceAt(ctx, newAddress, nil)
|
2021-12-29 21:01:09 +00:00
|
|
|
Expect(err).ToNot(HaveOccurred())
|
2023-04-14 06:26:46 +00:00
|
|
|
Expect(gethBalance.String()).To(Equal("10000000000000000"))
|
2021-12-29 21:01:09 +00:00
|
|
|
|
2023-04-14 06:26:46 +00:00
|
|
|
ipldBalance, err := ipldClient.BalanceAt(ctx, newAddress, nil)
|
2021-12-29 21:01:09 +00:00
|
|
|
Expect(err).ToNot(HaveOccurred())
|
2023-04-14 06:26:46 +00:00
|
|
|
Expect(ipldBalance.String()).To(Equal("0"))
|
2021-12-29 21:01:09 +00:00
|
|
|
})
|
|
|
|
It("gets balance for an account with eth with block number", func() {
|
2023-04-14 06:26:46 +00:00
|
|
|
_, err := gethClient.BalanceAt(ctx, newAddress, big.NewInt(tx.BlockNumber))
|
2021-12-29 21:01:09 +00:00
|
|
|
Expect(err).ToNot(HaveOccurred())
|
|
|
|
|
2023-04-14 06:26:46 +00:00
|
|
|
_, err = ipldClient.BalanceAt(ctx, newAddress, big.NewInt(tx.BlockNumber))
|
|
|
|
Expect(err).To(MatchError("header not found"))
|
2021-12-29 21:01:09 +00:00
|
|
|
})
|
|
|
|
It("gets historical balance for an account with eth with block number", func() {
|
2023-04-14 06:26:46 +00:00
|
|
|
_, err := gethClient.BalanceAt(ctx, newAddress, big.NewInt(tx.BlockNumber-1))
|
2021-12-29 21:01:09 +00:00
|
|
|
Expect(err).ToNot(HaveOccurred())
|
|
|
|
|
2023-04-14 06:26:46 +00:00
|
|
|
_, err = ipldClient.BalanceAt(ctx, newAddress, big.NewInt(tx.BlockNumber-1))
|
|
|
|
Expect(err).To(MatchError("header not found"))
|
2021-12-29 21:01:09 +00:00
|
|
|
})
|
|
|
|
|
2023-04-14 06:26:46 +00:00
|
|
|
It("gets balance for a non-existing account without block number", func() {
|
|
|
|
gethBalance, err := gethClient.BalanceAt(ctx, nonExistingAddress, nil)
|
2021-12-29 21:01:09 +00:00
|
|
|
Expect(err).ToNot(HaveOccurred())
|
|
|
|
|
2023-04-14 06:26:46 +00:00
|
|
|
ipldBalance, err := ipldClient.BalanceAt(ctx, nonExistingAddress, nil)
|
2021-12-29 21:01:09 +00:00
|
|
|
Expect(err).ToNot(HaveOccurred())
|
|
|
|
|
|
|
|
Expect(gethBalance).To(Equal(ipldBalance))
|
|
|
|
})
|
|
|
|
It("gets balance for an non-existing block number", func() {
|
2023-04-14 06:26:46 +00:00
|
|
|
gethBalance, err := gethClient.BalanceAt(ctx, newAddress, big.NewInt(tx.BlockNumber+3))
|
2021-12-29 21:01:09 +00:00
|
|
|
Expect(err).To(MatchError("header not found"))
|
|
|
|
|
2023-04-14 06:26:46 +00:00
|
|
|
ipldBalance, err := ipldClient.BalanceAt(ctx, nonExistingAddress, big.NewInt(tx.BlockNumber+3))
|
2021-12-29 21:01:09 +00:00
|
|
|
Expect(err).To(MatchError("header not found"))
|
|
|
|
|
|
|
|
Expect(gethBalance).To(Equal(ipldBalance))
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
Describe("Get Storage", func() {
|
|
|
|
BeforeEach(func() {
|
|
|
|
contract, contractErr = integration.DeployContract()
|
2023-04-14 06:26:46 +00:00
|
|
|
Expect(contractErr).ToNot(HaveOccurred())
|
2021-12-29 21:01:09 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
It("gets ERC20 total supply (without block number)", func() {
|
2023-04-14 06:26:46 +00:00
|
|
|
gethStorage, err := gethClient.StorageAt(ctx, contract.Address, ercTotalSupplyIndex, nil)
|
2021-12-29 21:01:09 +00:00
|
|
|
Expect(err).ToNot(HaveOccurred())
|
|
|
|
|
|
|
|
gethTotalSupply := new(big.Int).SetBytes(gethStorage)
|
|
|
|
Expect(gethTotalSupply).To(Equal(erc20TotalSupply))
|
|
|
|
|
2023-04-14 06:26:46 +00:00
|
|
|
ipldStorage, err := ipldClient.StorageAt(ctx, contract.Address, ercTotalSupplyIndex, nil)
|
2021-12-29 21:01:09 +00:00
|
|
|
Expect(err).ToNot(HaveOccurred())
|
2021-12-30 02:29:59 +00:00
|
|
|
Expect(ipldStorage).To(Equal(make([]byte, 32)))
|
2021-12-29 21:01:09 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
It("gets ERC20 total supply (with block number)", func() {
|
2023-04-14 06:26:46 +00:00
|
|
|
gethStorage, err := gethClient.StorageAt(ctx, contract.Address, ercTotalSupplyIndex, big.NewInt(contract.BlockNumber))
|
2021-12-29 21:01:09 +00:00
|
|
|
Expect(err).ToNot(HaveOccurred())
|
|
|
|
|
|
|
|
gethTotalSupply := new(big.Int).SetBytes(gethStorage)
|
|
|
|
Expect(gethTotalSupply).To(Equal(erc20TotalSupply))
|
|
|
|
|
2023-04-14 06:26:46 +00:00
|
|
|
_, err = ipldClient.StorageAt(ctx, contract.Address, ercTotalSupplyIndex, big.NewInt(contract.BlockNumber))
|
|
|
|
Expect(err).To(MatchError("header not found"))
|
2021-12-29 21:01:09 +00:00
|
|
|
})
|
|
|
|
|
2023-04-14 06:26:46 +00:00
|
|
|
It("gets storage for non-existing account", func() {
|
|
|
|
_, err := gethClient.StorageAt(ctx, nonExistingAddress, ercTotalSupplyIndex, big.NewInt(contract.BlockNumber))
|
2021-12-29 21:01:09 +00:00
|
|
|
Expect(err).ToNot(HaveOccurred())
|
|
|
|
|
2023-04-14 06:26:46 +00:00
|
|
|
_, err = ipldClient.StorageAt(ctx, nonExistingAddress, ercTotalSupplyIndex, big.NewInt(contract.BlockNumber))
|
2021-12-30 02:29:59 +00:00
|
|
|
Expect(err).To(MatchError("header not found"))
|
2021-12-29 21:01:09 +00:00
|
|
|
})
|
2023-04-14 06:26:46 +00:00
|
|
|
|
2021-12-29 21:01:09 +00:00
|
|
|
It("gets storage for non-existing contract slot", func() {
|
2023-04-14 06:26:46 +00:00
|
|
|
_, err := gethClient.StorageAt(ctx, contract.Address, randomHash, big.NewInt(contract.BlockNumber))
|
2021-12-29 21:01:09 +00:00
|
|
|
Expect(err).ToNot(HaveOccurred())
|
|
|
|
|
2023-04-14 06:26:46 +00:00
|
|
|
_, err = ipldClient.StorageAt(ctx, contract.Address, randomHash, big.NewInt(contract.BlockNumber))
|
2021-12-30 02:29:59 +00:00
|
|
|
Expect(err).To(MatchError("header not found"))
|
2021-12-29 21:01:09 +00:00
|
|
|
})
|
2023-04-14 06:26:46 +00:00
|
|
|
|
2021-12-29 21:01:09 +00:00
|
|
|
It("gets storage for non-existing contract", func() {
|
2023-04-14 06:26:46 +00:00
|
|
|
gethStorage, err := gethClient.StorageAt(ctx, contract.Address, ercTotalSupplyIndex, big.NewInt(0))
|
2021-12-29 21:01:09 +00:00
|
|
|
Expect(err).ToNot(HaveOccurred())
|
|
|
|
|
2023-04-14 06:26:46 +00:00
|
|
|
ipldStorage, err := ipldClient.StorageAt(ctx, contract.Address, ercTotalSupplyIndex, big.NewInt(0))
|
2021-12-29 21:01:09 +00:00
|
|
|
Expect(err).ToNot(HaveOccurred())
|
|
|
|
Expect(gethStorage).To(Equal(ipldStorage))
|
|
|
|
})
|
2023-04-14 06:26:46 +00:00
|
|
|
|
2021-12-29 21:01:09 +00:00
|
|
|
It("gets storage for non-existing block number", func() {
|
|
|
|
blockNum := contract.BlockNumber + 100
|
|
|
|
|
2023-04-14 06:26:46 +00:00
|
|
|
gethStorage, err := gethClient.StorageAt(ctx, contract.Address, ercTotalSupplyIndex, big.NewInt(blockNum))
|
2021-12-29 21:01:09 +00:00
|
|
|
Expect(err).To(MatchError("header not found"))
|
|
|
|
|
2023-04-14 06:26:46 +00:00
|
|
|
ipldStorage, err := ipldClient.StorageAt(ctx, contract.Address, ercTotalSupplyIndex, big.NewInt(blockNum))
|
2021-12-29 21:01:09 +00:00
|
|
|
Expect(err).To(MatchError("header not found"))
|
|
|
|
Expect(gethStorage).To(Equal(ipldStorage))
|
|
|
|
})
|
|
|
|
|
|
|
|
It("get storage after self destruct", func() {
|
|
|
|
tx, err := integration.DestroyContract(contract.Address)
|
|
|
|
Expect(err).ToNot(HaveOccurred())
|
|
|
|
|
2023-04-14 06:26:46 +00:00
|
|
|
gethStorage1, err := gethClient.StorageAt(ctx, contract.Address, ercTotalSupplyIndex, big.NewInt(tx.BlockNumber-1))
|
2021-12-29 21:01:09 +00:00
|
|
|
Expect(err).ToNot(HaveOccurred())
|
2023-04-14 06:26:46 +00:00
|
|
|
gethStorage2, err := gethClient.StorageAt(ctx, contract.Address, ercTotalSupplyIndex, big.NewInt(tx.BlockNumber))
|
2021-12-29 21:01:09 +00:00
|
|
|
Expect(err).ToNot(HaveOccurred())
|
|
|
|
|
|
|
|
Expect(gethStorage1).NotTo(Equal(gethStorage2))
|
|
|
|
Expect(gethStorage2).To(Equal(eth.EmptyNodeValue))
|
|
|
|
|
2023-04-14 06:26:46 +00:00
|
|
|
_, err = ipldClient.StorageAt(ctx, contract.Address, ercTotalSupplyIndex, big.NewInt(tx.BlockNumber-1))
|
|
|
|
Expect(err).To(MatchError("header not found"))
|
|
|
|
|
|
|
|
_, err = ipldClient.StorageAt(ctx, contract.Address, ercTotalSupplyIndex, big.NewInt(tx.BlockNumber))
|
2021-12-30 02:29:59 +00:00
|
|
|
Expect(err).To(MatchError("header not found"))
|
2021-12-29 21:01:09 +00:00
|
|
|
|
|
|
|
// Query the current block
|
2023-04-14 06:26:46 +00:00
|
|
|
ipldStorage3, err := ipldClient.StorageAt(ctx, contract.Address, ercTotalSupplyIndex, nil)
|
2021-12-29 21:01:09 +00:00
|
|
|
Expect(err).ToNot(HaveOccurred())
|
|
|
|
|
2021-12-30 02:29:59 +00:00
|
|
|
Expect(eth.EmptyNodeValue).To(Equal(ipldStorage3))
|
2021-12-29 21:01:09 +00:00
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
Describe("eth call", func() {
|
2023-04-14 06:26:46 +00:00
|
|
|
var msg ethereum.CallMsg
|
|
|
|
|
2021-12-29 21:01:09 +00:00
|
|
|
BeforeEach(func() {
|
|
|
|
contract, contractErr = integration.DeployContract()
|
|
|
|
Expect(contractErr).ToNot(HaveOccurred())
|
|
|
|
|
2023-04-14 06:26:46 +00:00
|
|
|
msg = ethereum.CallMsg{
|
|
|
|
To: &contract.Address,
|
2021-12-29 21:01:09 +00:00
|
|
|
Data: common.Hex2Bytes("18160ddd"), // totalSupply()
|
|
|
|
}
|
2023-04-14 06:26:46 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
It("calls totalSupply() without block number", func() {
|
2021-12-29 21:01:09 +00:00
|
|
|
gethResult, err := gethClient.CallContract(ctx, msg, nil)
|
|
|
|
Expect(err).ToNot(HaveOccurred())
|
|
|
|
|
|
|
|
gethTotalSupply := new(big.Int).SetBytes(gethResult)
|
|
|
|
Expect(gethTotalSupply).To(Equal(erc20TotalSupply))
|
|
|
|
|
|
|
|
ipldResult, err := ipldClient.CallContract(ctx, msg, nil)
|
|
|
|
Expect(err).ToNot(HaveOccurred())
|
|
|
|
|
|
|
|
Expect(gethResult).To(Equal(ipldResult))
|
|
|
|
})
|
|
|
|
|
|
|
|
It("calls totalSupply() with block number", func() {
|
2023-04-14 06:26:46 +00:00
|
|
|
gethResult, err := gethClient.CallContract(ctx, msg, big.NewInt(contract.BlockNumber))
|
2021-12-29 21:01:09 +00:00
|
|
|
Expect(err).ToNot(HaveOccurred())
|
|
|
|
|
|
|
|
gethTotalSupply := new(big.Int).SetBytes(gethResult)
|
|
|
|
Expect(gethTotalSupply).To(Equal(erc20TotalSupply))
|
|
|
|
|
2023-04-14 06:26:46 +00:00
|
|
|
ipldResult, err := ipldClient.CallContract(ctx, msg, big.NewInt(contract.BlockNumber))
|
2021-12-29 21:01:09 +00:00
|
|
|
Expect(err).ToNot(HaveOccurred())
|
|
|
|
|
|
|
|
Expect(gethResult).To(Equal(ipldResult))
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
Describe("Chain ID", func() {
|
|
|
|
It("Check chain id", func() {
|
2021-12-30 02:29:59 +00:00
|
|
|
_, err := gethClient.ChainID(ctx)
|
2021-12-29 21:01:09 +00:00
|
|
|
Expect(err).ToNot(HaveOccurred())
|
|
|
|
|
2021-12-30 02:29:59 +00:00
|
|
|
_, err = ipldClient.ChainID(ctx)
|
2022-08-02 20:18:36 +00:00
|
|
|
Expect(err).ToNot(HaveOccurred())
|
2021-12-29 21:01:09 +00:00
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|