2021-04-16 13:57:11 +00:00
|
|
|
package integration_test
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
2021-06-03 16:49:48 +00:00
|
|
|
"math/big"
|
2023-04-14 06:26:46 +00:00
|
|
|
"math/rand"
|
2021-06-03 16:49:48 +00:00
|
|
|
|
2021-04-19 08:32:36 +00:00
|
|
|
"github.com/ethereum/go-ethereum"
|
|
|
|
"github.com/ethereum/go-ethereum/common"
|
2021-04-19 12:40:42 +00:00
|
|
|
"github.com/ethereum/go-ethereum/core/types"
|
2021-06-10 04:36:27 +00:00
|
|
|
"github.com/ethereum/go-ethereum/crypto"
|
2023-04-14 06:26:46 +00:00
|
|
|
. "github.com/onsi/ginkgo/v2"
|
2021-04-16 13:57:11 +00:00
|
|
|
. "github.com/onsi/gomega"
|
|
|
|
|
2023-05-26 06:12:01 +00:00
|
|
|
integration "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-04-16 13:57:11 +00:00
|
|
|
)
|
|
|
|
|
2021-06-10 04:36:27 +00:00
|
|
|
var (
|
2023-04-14 06:26:46 +00:00
|
|
|
nonExistingBlockHash = common.HexToHash("0x111111111111111111111111111111111111111111111111111111111111111")
|
|
|
|
nonExistingAddress = common.HexToAddress("0x1111111111111111111111111111111111111111")
|
|
|
|
randomAddr = common.HexToAddress("0x1C3ab14BBaD3D99F4203bd7a11aCB94882050E6f")
|
|
|
|
randomHash = crypto.Keccak256Hash(randomAddr.Bytes())
|
2021-06-10 04:36:27 +00:00
|
|
|
|
2023-04-14 06:26:46 +00:00
|
|
|
erc20TotalSupply, _ = new(big.Int).SetString("1000000000000000000000", 10)
|
|
|
|
ercTotalSupplyIndex = common.HexToHash("0x2")
|
|
|
|
)
|
2021-04-16 13:57:11 +00:00
|
|
|
|
2023-04-14 06:26:46 +00:00
|
|
|
var _ = Describe("Basic integration test", func() {
|
2021-04-19 08:32:36 +00:00
|
|
|
ctx := context.Background()
|
|
|
|
|
|
|
|
var contract *integration.ContractDeployed
|
2021-04-23 09:46:35 +00:00
|
|
|
var tx *integration.Tx
|
2021-04-19 08:32:36 +00:00
|
|
|
var contractErr error
|
2021-04-23 09:46:35 +00:00
|
|
|
var txErr error
|
2022-03-16 16:15:31 +00:00
|
|
|
|
2024-04-18 13:54:42 +00:00
|
|
|
Describe("Get Block", func() {
|
2021-04-21 19:26:55 +00:00
|
|
|
BeforeEach(func() {
|
|
|
|
contract, contractErr = integration.DeployContract()
|
2023-04-14 06:26:46 +00:00
|
|
|
Expect(contractErr).ToNot(HaveOccurred())
|
|
|
|
|
2023-05-28 11:01:14 +00:00
|
|
|
err := waitForBlock(ctx, ipldClient, contract.BlockNumber)
|
|
|
|
Expect(err).ToNot(HaveOccurred())
|
2021-04-21 19:26:55 +00:00
|
|
|
})
|
2021-04-19 08:32:36 +00:00
|
|
|
|
2024-04-18 13:54:42 +00:00
|
|
|
It("gets not existing block by number", func() {
|
2023-04-14 06:26:46 +00:00
|
|
|
blockNum := big.NewInt(contract.BlockNumber + 100)
|
2021-04-19 08:32:36 +00:00
|
|
|
|
2023-04-14 06:26:46 +00:00
|
|
|
gethBlock, err := gethClient.BlockByNumber(ctx, blockNum)
|
2021-04-19 11:43:21 +00:00
|
|
|
Expect(err).To(MatchError(ethereum.NotFound))
|
|
|
|
Expect(gethBlock).To(BeZero())
|
2021-04-19 08:32:36 +00:00
|
|
|
|
2023-04-14 06:26:46 +00:00
|
|
|
ipldBlock, err := ipldClient.BlockByNumber(ctx, blockNum)
|
2021-04-19 11:43:21 +00:00
|
|
|
Expect(err).To(MatchError(ethereum.NotFound))
|
|
|
|
Expect(ipldBlock).To(BeZero())
|
2021-04-19 08:32:36 +00:00
|
|
|
})
|
|
|
|
|
2024-04-18 13:54:42 +00:00
|
|
|
It("gets not existing block by hash", func() {
|
2023-04-14 06:26:46 +00:00
|
|
|
gethBlock, err := gethClient.BlockByHash(ctx, nonExistingBlockHash)
|
2021-04-19 11:43:21 +00:00
|
|
|
Expect(err).To(MatchError(ethereum.NotFound))
|
|
|
|
Expect(gethBlock).To(BeZero())
|
2021-04-16 13:57:11 +00:00
|
|
|
|
2023-04-14 06:26:46 +00:00
|
|
|
ipldBlock, err := ipldClient.BlockByHash(ctx, nonExistingBlockHash)
|
2021-04-19 11:43:21 +00:00
|
|
|
Expect(err).To(MatchError(ethereum.NotFound))
|
|
|
|
Expect(ipldBlock).To(BeZero())
|
2021-04-19 08:32:36 +00:00
|
|
|
})
|
|
|
|
|
2024-04-18 13:54:42 +00:00
|
|
|
It("gets block by number", func() {
|
2023-04-14 06:26:46 +00:00
|
|
|
blockNum := big.NewInt(contract.BlockNumber)
|
2021-04-19 12:40:42 +00:00
|
|
|
|
2023-04-14 06:26:46 +00:00
|
|
|
gethBlock, err := gethClient.BlockByNumber(ctx, blockNum)
|
2021-04-19 12:40:42 +00:00
|
|
|
Expect(err).ToNot(HaveOccurred())
|
|
|
|
|
2023-04-14 06:26:46 +00:00
|
|
|
ipldBlock, err := ipldClient.BlockByNumber(ctx, blockNum)
|
2021-04-19 12:40:42 +00:00
|
|
|
Expect(err).ToNot(HaveOccurred())
|
|
|
|
|
|
|
|
// check headers are equals
|
|
|
|
Expect(gethBlock.Header()).To(Equal(ipldBlock.Header()))
|
|
|
|
|
|
|
|
gethTxs := gethBlock.Transactions()
|
|
|
|
ipldTxs := ipldBlock.Transactions()
|
|
|
|
|
|
|
|
Expect(gethTxs.Len()).To(Equal(ipldTxs.Len()))
|
|
|
|
Expect(types.TxDifference(gethTxs, ipldTxs).Len()).To(Equal(0))
|
|
|
|
})
|
|
|
|
|
2024-04-18 13:54:42 +00:00
|
|
|
It("gets block by hash", func() {
|
2023-04-14 06:26:46 +00:00
|
|
|
gethBlock, err := gethClient.BlockByHash(ctx, contract.BlockHash)
|
2021-04-19 12:40:42 +00:00
|
|
|
Expect(err).ToNot(HaveOccurred())
|
|
|
|
|
2023-04-14 06:26:46 +00:00
|
|
|
ipldBlock, err := ipldClient.BlockByHash(ctx, contract.BlockHash)
|
2021-04-19 12:40:42 +00:00
|
|
|
Expect(err).ToNot(HaveOccurred())
|
|
|
|
|
|
|
|
// check headers are equals
|
2021-04-29 13:33:27 +00:00
|
|
|
compareBlocks(gethBlock, ipldBlock)
|
2021-04-19 12:40:42 +00:00
|
|
|
|
|
|
|
gethTxs := gethBlock.Transactions()
|
|
|
|
ipldTxs := ipldBlock.Transactions()
|
|
|
|
|
|
|
|
Expect(gethTxs.Len()).To(Equal(ipldTxs.Len()))
|
|
|
|
Expect(types.TxDifference(gethTxs, ipldTxs).Len()).To(Equal(0))
|
|
|
|
})
|
2021-04-19 08:32:36 +00:00
|
|
|
})
|
|
|
|
|
2021-04-19 12:40:42 +00:00
|
|
|
Describe("Transaction", func() {
|
2021-04-21 19:26:55 +00:00
|
|
|
BeforeEach(func() {
|
|
|
|
contract, contractErr = integration.DeployContract()
|
2023-04-14 06:26:46 +00:00
|
|
|
Expect(contractErr).ToNot(HaveOccurred())
|
2021-04-21 19:26:55 +00:00
|
|
|
})
|
2021-04-19 12:40:42 +00:00
|
|
|
|
|
|
|
It("Get tx by hash", func() {
|
2023-04-14 06:26:46 +00:00
|
|
|
gethTx, _, err := gethClient.TransactionByHash(ctx, contract.TransactionHash)
|
2021-04-19 12:40:42 +00:00
|
|
|
Expect(err).ToNot(HaveOccurred())
|
|
|
|
|
2023-04-14 06:26:46 +00:00
|
|
|
ipldTx, _, err := ipldClient.TransactionByHash(ctx, contract.TransactionHash)
|
2021-04-19 12:40:42 +00:00
|
|
|
Expect(err).ToNot(HaveOccurred())
|
|
|
|
|
2021-04-29 13:33:27 +00:00
|
|
|
compareTxs(gethTx, ipldTx)
|
2021-04-19 12:40:42 +00:00
|
|
|
|
|
|
|
Expect(gethTx.Hash()).To(Equal(ipldTx.Hash()))
|
|
|
|
})
|
|
|
|
|
|
|
|
It("Get tx by block hash and index", func() {
|
2023-04-14 06:26:46 +00:00
|
|
|
gethTx, err := gethClient.TransactionInBlock(ctx, contract.BlockHash, 0)
|
2021-04-19 12:40:42 +00:00
|
|
|
Expect(err).ToNot(HaveOccurred())
|
|
|
|
|
2023-04-14 06:26:46 +00:00
|
|
|
ipldTx, err := ipldClient.TransactionInBlock(ctx, contract.BlockHash, 0)
|
2021-04-19 12:40:42 +00:00
|
|
|
Expect(err).ToNot(HaveOccurred())
|
|
|
|
|
2021-04-29 13:33:27 +00:00
|
|
|
compareTxs(gethTx, ipldTx)
|
2021-04-19 12:40:42 +00:00
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
Describe("Receipt", func() {
|
2021-04-21 19:26:55 +00:00
|
|
|
BeforeEach(func() {
|
|
|
|
contract, contractErr = integration.DeployContract()
|
2023-04-14 06:26:46 +00:00
|
|
|
Expect(contractErr).ToNot(HaveOccurred())
|
2021-04-21 19:26:55 +00:00
|
|
|
})
|
2021-04-19 12:40:42 +00:00
|
|
|
|
|
|
|
It("Get tx receipt", func() {
|
2023-04-14 06:26:46 +00:00
|
|
|
gethReceipt, err := gethClient.TransactionReceipt(ctx, contract.TransactionHash)
|
2021-04-19 12:40:42 +00:00
|
|
|
Expect(err).ToNot(HaveOccurred())
|
|
|
|
|
2023-04-14 06:26:46 +00:00
|
|
|
ipldReceipt, err := ipldClient.TransactionReceipt(ctx, contract.TransactionHash)
|
2021-04-19 12:40:42 +00:00
|
|
|
Expect(err).ToNot(HaveOccurred())
|
|
|
|
|
|
|
|
Expect(gethReceipt).To(Equal(ipldReceipt))
|
|
|
|
|
2023-06-12 22:25:17 +00:00
|
|
|
rlpGeth, err := gethReceipt.MarshalBinary()
|
2021-04-19 12:40:42 +00:00
|
|
|
Expect(err).ToNot(HaveOccurred())
|
|
|
|
|
2023-06-12 22:25:17 +00:00
|
|
|
rlpIpld, err := ipldReceipt.MarshalBinary()
|
2021-04-19 12:40:42 +00:00
|
|
|
Expect(err).ToNot(HaveOccurred())
|
|
|
|
|
|
|
|
Expect(rlpGeth).To(Equal(rlpIpld))
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
Describe("FilterLogs", func() {
|
2021-04-21 19:26:55 +00:00
|
|
|
BeforeEach(func() {
|
|
|
|
contract, contractErr = integration.DeployContract()
|
2023-04-14 06:26:46 +00:00
|
|
|
Expect(contractErr).ToNot(HaveOccurred())
|
2021-04-21 19:26:55 +00:00
|
|
|
})
|
2021-04-19 12:40:42 +00:00
|
|
|
|
|
|
|
It("with blockhash", func() {
|
2023-04-14 06:26:46 +00:00
|
|
|
blockHash := contract.BlockHash
|
2021-04-19 12:40:42 +00:00
|
|
|
filterQuery := ethereum.FilterQuery{
|
|
|
|
//Addresses: addresses,
|
|
|
|
BlockHash: &blockHash,
|
|
|
|
Topics: [][]common.Hash{},
|
|
|
|
}
|
|
|
|
|
|
|
|
gethLogs, err := gethClient.FilterLogs(ctx, filterQuery)
|
|
|
|
Expect(err).ToNot(HaveOccurred())
|
|
|
|
|
|
|
|
ipldLogs, err := ipldClient.FilterLogs(ctx, filterQuery)
|
|
|
|
Expect(err).ToNot(HaveOccurred())
|
|
|
|
|
|
|
|
// not empty list
|
|
|
|
Expect(gethLogs).ToNot(BeEmpty())
|
|
|
|
|
|
|
|
Expect(len(gethLogs)).To(Equal(len(ipldLogs)))
|
|
|
|
Expect(gethLogs).To(Equal(ipldLogs))
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2021-04-23 09:46:35 +00:00
|
|
|
Describe("CodeAt", func() {
|
2021-04-21 19:26:55 +00:00
|
|
|
BeforeEach(func() {
|
|
|
|
contract, contractErr = integration.DeployContract()
|
2023-04-14 06:26:46 +00:00
|
|
|
Expect(contractErr).ToNot(HaveOccurred())
|
2021-04-21 19:26:55 +00:00
|
|
|
})
|
2021-04-21 11:16:47 +00:00
|
|
|
|
|
|
|
It("gets code at non-existing address without block number", func() {
|
2023-04-14 06:26:46 +00:00
|
|
|
gethCode, err := gethClient.CodeAt(ctx, nonExistingAddress, nil)
|
2021-04-21 11:16:47 +00:00
|
|
|
Expect(err).ToNot(HaveOccurred())
|
|
|
|
|
2023-04-14 06:26:46 +00:00
|
|
|
ipldCode, err := ipldClient.CodeAt(ctx, nonExistingAddress, nil)
|
2021-04-21 11:16:47 +00:00
|
|
|
Expect(err).ToNot(HaveOccurred())
|
|
|
|
|
|
|
|
Expect(gethCode).To(BeEmpty())
|
|
|
|
Expect(gethCode).To(Equal(ipldCode))
|
|
|
|
})
|
|
|
|
It("gets code of deployed contract without block number", func() {
|
2023-04-14 06:26:46 +00:00
|
|
|
gethCode, err := gethClient.CodeAt(ctx, contract.Address, nil)
|
2021-04-19 12:40:42 +00:00
|
|
|
Expect(err).ToNot(HaveOccurred())
|
|
|
|
|
2023-04-14 06:26:46 +00:00
|
|
|
ipldCode, err := ipldClient.CodeAt(ctx, contract.Address, nil)
|
2021-04-19 12:40:42 +00:00
|
|
|
Expect(err).ToNot(HaveOccurred())
|
2021-04-21 12:11:00 +00:00
|
|
|
Expect(gethCode).To(Equal(ipldCode))
|
|
|
|
})
|
2021-04-21 13:05:24 +00:00
|
|
|
It("gets code of deployed contract with block number", func() {
|
2023-04-14 06:26:46 +00:00
|
|
|
gethCode, err := gethClient.CodeAt(ctx, contract.Address, big.NewInt(contract.BlockNumber))
|
2021-04-21 13:05:24 +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))
|
2021-04-21 13:05:24 +00:00
|
|
|
Expect(err).ToNot(HaveOccurred())
|
|
|
|
Expect(gethCode).To(Equal(ipldCode))
|
|
|
|
})
|
2021-04-21 12:11:00 +00:00
|
|
|
It("gets code of contract that doesn't exist at this height", func() {
|
2023-04-14 06:26:46 +00:00
|
|
|
gethCode, err := gethClient.CodeAt(ctx, contract.Address, big.NewInt(contract.BlockNumber-1))
|
2021-04-21 12:11:00 +00:00
|
|
|
Expect(err).ToNot(HaveOccurred())
|
2021-04-19 12:40:42 +00:00
|
|
|
|
2023-04-14 06:26:46 +00:00
|
|
|
ipldCode, err := ipldClient.CodeAt(ctx, contract.Address, big.NewInt(contract.BlockNumber-1))
|
2021-04-21 12:11:00 +00:00
|
|
|
Expect(err).ToNot(HaveOccurred())
|
|
|
|
|
|
|
|
Expect(gethCode).To(BeEmpty())
|
2021-04-19 12:40:42 +00:00
|
|
|
Expect(gethCode).To(Equal(ipldCode))
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2021-04-21 13:05:24 +00:00
|
|
|
Describe("Get balance", func() {
|
2023-04-14 06:26:46 +00:00
|
|
|
var newAddress common.Address
|
|
|
|
rand.Read(newAddress[:])
|
2021-04-21 13:05:24 +00:00
|
|
|
|
2023-04-14 06:26:46 +00:00
|
|
|
BeforeEach(func() {
|
|
|
|
tx, txErr = integration.SendEth(newAddress, "0.01")
|
2021-04-21 13:05:24 +00:00
|
|
|
Expect(txErr).ToNot(HaveOccurred())
|
2023-04-14 06:26:46 +00:00
|
|
|
})
|
2021-04-21 13:05:24 +00:00
|
|
|
|
2023-04-14 06:26:46 +00:00
|
|
|
It("gets balance for an account with eth with block number", func() {
|
|
|
|
gethBalance, err := gethClient.BalanceAt(ctx, newAddress, big.NewInt(tx.BlockNumber))
|
2021-04-21 13:05:24 +00:00
|
|
|
Expect(err).ToNot(HaveOccurred())
|
|
|
|
|
2023-04-14 06:26:46 +00:00
|
|
|
ipldBalance, err := ipldClient.BalanceAt(ctx, newAddress, big.NewInt(tx.BlockNumber))
|
2021-04-21 13:05:24 +00:00
|
|
|
Expect(err).ToNot(HaveOccurred())
|
|
|
|
|
|
|
|
Expect(gethBalance).To(Equal(ipldBalance))
|
|
|
|
})
|
2023-04-14 06:26:46 +00:00
|
|
|
It("gets balance for an account with eth without block number", func() {
|
|
|
|
gethBalance, err := gethClient.BalanceAt(ctx, newAddress, nil)
|
2021-04-21 13:05:24 +00:00
|
|
|
Expect(err).ToNot(HaveOccurred())
|
|
|
|
|
2023-04-14 06:26:46 +00:00
|
|
|
ipldBalance, err := ipldClient.BalanceAt(ctx, newAddress, nil)
|
2021-04-21 13:05:24 +00:00
|
|
|
Expect(err).ToNot(HaveOccurred())
|
|
|
|
|
|
|
|
Expect(gethBalance).To(Equal(ipldBalance))
|
|
|
|
})
|
|
|
|
|
2023-04-14 06:26:46 +00:00
|
|
|
It("gets historical balance for an account with eth with block number", func() {
|
|
|
|
gethBalance, err := gethClient.BalanceAt(ctx, newAddress, big.NewInt(tx.BlockNumber-1))
|
2021-04-21 13:05:24 +00:00
|
|
|
Expect(err).ToNot(HaveOccurred())
|
|
|
|
|
2023-04-14 06:26:46 +00:00
|
|
|
ipldBalance, err := ipldClient.BalanceAt(ctx, newAddress, big.NewInt(tx.BlockNumber-1))
|
2021-04-21 13:05:24 +00:00
|
|
|
Expect(err).ToNot(HaveOccurred())
|
|
|
|
|
2021-04-23 09:46:35 +00:00
|
|
|
Expect(gethBalance).To(Equal(ipldBalance))
|
|
|
|
})
|
|
|
|
It("gets balance for a non-existing account without block number", func() {
|
2023-04-14 06:26:46 +00:00
|
|
|
gethBalance, err := gethClient.BalanceAt(ctx, nonExistingAddress, nil)
|
2021-04-23 09:46:35 +00:00
|
|
|
Expect(err).ToNot(HaveOccurred())
|
|
|
|
|
2023-04-14 06:26:46 +00:00
|
|
|
ipldBalance, err := ipldClient.BalanceAt(ctx, nonExistingAddress, nil)
|
2021-04-23 09:46:35 +00:00
|
|
|
Expect(err).ToNot(HaveOccurred())
|
|
|
|
|
2021-06-09 18:50:12 +00:00
|
|
|
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-06-09 18:50:12 +00:00
|
|
|
Expect(err).To(MatchError("header not found"))
|
|
|
|
|
2023-04-14 06:26:46 +00:00
|
|
|
ipldBalance, err := ipldClient.BalanceAt(ctx, newAddress, big.NewInt(tx.BlockNumber+3))
|
2021-06-09 18:50:12 +00:00
|
|
|
Expect(err).To(MatchError("header not found"))
|
|
|
|
|
2021-04-21 13:05:24 +00:00
|
|
|
Expect(gethBalance).To(Equal(ipldBalance))
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2021-04-21 13:38:02 +00:00
|
|
|
Describe("Get Storage", func() {
|
2023-04-14 06:26:46 +00:00
|
|
|
var contractSalt string
|
|
|
|
countAIndex := common.HexToHash("0x5")
|
2022-03-17 12:01:01 +00:00
|
|
|
|
2021-04-21 19:26:55 +00:00
|
|
|
BeforeEach(func() {
|
|
|
|
contract, contractErr = integration.DeployContract()
|
2021-04-21 13:38:02 +00:00
|
|
|
Expect(contractErr).ToNot(HaveOccurred())
|
2023-04-14 06:26:46 +00:00
|
|
|
Expect(contract.BlockNumber).ToNot(BeZero())
|
2021-04-21 13:38:02 +00:00
|
|
|
|
2023-04-14 06:26:46 +00:00
|
|
|
contractSalt = common.Bytes2Hex(contract.BlockHash[:10])
|
2023-05-28 11:01:14 +00:00
|
|
|
|
|
|
|
err := waitForBlock(ctx, ipldClient, contract.BlockNumber)
|
|
|
|
Expect(err).ToNot(HaveOccurred())
|
2023-04-14 06:26:46 +00:00
|
|
|
})
|
2021-04-21 13:38:02 +00:00
|
|
|
|
2023-04-14 06:26:46 +00:00
|
|
|
It("gets ERC20 total supply (with block number)", func() {
|
|
|
|
gethStorage, err := gethClient.StorageAt(ctx, contract.Address, ercTotalSupplyIndex, big.NewInt(contract.BlockNumber))
|
2021-04-21 13:38:02 +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, big.NewInt(contract.BlockNumber))
|
2021-04-21 13:38:02 +00:00
|
|
|
Expect(err).ToNot(HaveOccurred())
|
|
|
|
Expect(gethStorage).To(Equal(ipldStorage))
|
|
|
|
})
|
|
|
|
|
2023-04-14 06:26:46 +00:00
|
|
|
It("gets ERC20 total supply (without block number)", func() {
|
|
|
|
gethStorage, err := gethClient.StorageAt(ctx, contract.Address, ercTotalSupplyIndex, nil)
|
2021-04-21 13:38:02 +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-04-21 13:38:02 +00:00
|
|
|
Expect(err).ToNot(HaveOccurred())
|
2023-04-14 06:26:46 +00:00
|
|
|
|
2021-04-21 13:38:02 +00:00
|
|
|
Expect(gethStorage).To(Equal(ipldStorage))
|
|
|
|
})
|
2021-04-23 09:46:35 +00:00
|
|
|
|
2023-04-14 06:26:46 +00:00
|
|
|
It("gets storage for non-existing account", func() {
|
|
|
|
gethStorage, err := gethClient.StorageAt(ctx, nonExistingAddress, ercTotalSupplyIndex, big.NewInt(contract.BlockNumber))
|
2021-04-23 09:46:35 +00:00
|
|
|
Expect(err).ToNot(HaveOccurred())
|
|
|
|
|
2023-04-14 06:26:46 +00:00
|
|
|
ipldStorage, err := ipldClient.StorageAt(ctx, nonExistingAddress, ercTotalSupplyIndex, big.NewInt(contract.BlockNumber))
|
2021-06-10 04:36:27 +00:00
|
|
|
Expect(err).ToNot(HaveOccurred())
|
|
|
|
Expect(gethStorage).To(Equal(ipldStorage))
|
|
|
|
})
|
2023-04-14 06:26:46 +00:00
|
|
|
|
2021-06-10 04:36:27 +00:00
|
|
|
It("gets storage for non-existing contract slot", func() {
|
2023-04-14 06:26:46 +00:00
|
|
|
gethStorage, err := gethClient.StorageAt(ctx, contract.Address, randomHash, big.NewInt(contract.BlockNumber))
|
2021-06-10 04:36:27 +00:00
|
|
|
Expect(err).ToNot(HaveOccurred())
|
|
|
|
|
2023-04-14 06:26:46 +00:00
|
|
|
ipldStorage, err := ipldClient.StorageAt(ctx, contract.Address, randomHash, big.NewInt(contract.BlockNumber))
|
2021-06-10 04:36:27 +00:00
|
|
|
Expect(err).ToNot(HaveOccurred())
|
|
|
|
Expect(gethStorage).To(Equal(ipldStorage))
|
|
|
|
})
|
2023-04-14 06:26:46 +00:00
|
|
|
|
2021-06-10 04:36:27 +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-06-10 04:36:27 +00:00
|
|
|
Expect(err).ToNot(HaveOccurred())
|
2021-04-23 09:46:35 +00:00
|
|
|
|
2023-04-14 06:26:46 +00:00
|
|
|
ipldStorage, err := ipldClient.StorageAt(ctx, contract.Address, ercTotalSupplyIndex, big.NewInt(0))
|
2021-04-23 09:46:35 +00:00
|
|
|
Expect(err).ToNot(HaveOccurred())
|
|
|
|
Expect(gethStorage).To(Equal(ipldStorage))
|
|
|
|
})
|
2023-04-14 06:26:46 +00:00
|
|
|
|
2021-06-10 06:20:25 +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-06-10 06:20:25 +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-06-10 06:20:25 +00:00
|
|
|
Expect(err).To(MatchError("header not found"))
|
|
|
|
Expect(gethStorage).To(Equal(ipldStorage))
|
|
|
|
})
|
2021-09-06 14:44:06 +00:00
|
|
|
|
2023-04-14 06:26:46 +00:00
|
|
|
It("gets storage for SLV countA after tx", func() {
|
|
|
|
slvContract, contractErr := integration.Create2Contract("SLVToken", contractSalt)
|
2022-03-17 12:01:01 +00:00
|
|
|
Expect(contractErr).ToNot(HaveOccurred())
|
|
|
|
|
2023-04-14 06:26:46 +00:00
|
|
|
gethStorage, err := gethClient.StorageAt(ctx, slvContract.Address, countAIndex, big.NewInt(slvContract.BlockNumber))
|
2022-03-17 12:01:01 +00:00
|
|
|
Expect(err).ToNot(HaveOccurred())
|
|
|
|
|
2023-04-14 06:26:46 +00:00
|
|
|
slvCountA := new(big.Int).SetBytes(gethStorage)
|
2022-03-17 12:01:01 +00:00
|
|
|
|
2023-04-14 06:26:46 +00:00
|
|
|
err = waitForBlock(ctx, ipldClient, slvContract.BlockNumber)
|
|
|
|
Expect(err).ToNot(HaveOccurred())
|
|
|
|
|
|
|
|
ipldStorage, err := ipldClient.StorageAt(ctx, slvContract.Address, countAIndex, big.NewInt(slvContract.BlockNumber))
|
2022-03-17 12:01:01 +00:00
|
|
|
Expect(err).ToNot(HaveOccurred())
|
|
|
|
|
|
|
|
ipldCountA := new(big.Int).SetBytes(ipldStorage)
|
2023-04-14 06:26:46 +00:00
|
|
|
Expect(ipldCountA).To(Equal(slvCountA))
|
2022-03-17 12:01:01 +00:00
|
|
|
|
2023-04-14 06:26:46 +00:00
|
|
|
inc, err := integration.IncrementCount("A", slvContract.Address)
|
|
|
|
Expect(err).ToNot(HaveOccurred())
|
2022-03-17 12:01:01 +00:00
|
|
|
slvCountA.Add(slvCountA, big.NewInt(1))
|
|
|
|
|
2023-04-14 06:26:46 +00:00
|
|
|
ipldStorage, err = ipldClient.StorageAt(ctx, slvContract.Address, countAIndex, inc.BlockNumber)
|
2022-03-17 12:01:01 +00:00
|
|
|
Expect(err).ToNot(HaveOccurred())
|
|
|
|
|
|
|
|
ipldCountA = new(big.Int).SetBytes(ipldStorage)
|
2023-04-14 06:26:46 +00:00
|
|
|
Expect(ipldCountA).To(Equal(slvCountA))
|
2022-03-17 12:01:01 +00:00
|
|
|
})
|
|
|
|
|
2024-04-18 11:02:29 +00:00
|
|
|
It("gets storage after destruction", func() {
|
2023-04-14 06:26:46 +00:00
|
|
|
slvContract, contractErr := integration.Create2Contract("SLVToken", contractSalt)
|
|
|
|
Expect(contractErr).ToNot(HaveOccurred())
|
2021-09-06 14:44:06 +00:00
|
|
|
|
2021-09-22 11:00:10 +00:00
|
|
|
tx, err := integration.DestroyContract(contract.Address)
|
2021-09-06 14:44:06 +00:00
|
|
|
Expect(err).ToNot(HaveOccurred())
|
|
|
|
|
2022-03-17 12:01:01 +00:00
|
|
|
slvTx, err := integration.DestroyContract(slvContract.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-09-06 14:44:06 +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-09-06 14:44:06 +00:00
|
|
|
Expect(err).ToNot(HaveOccurred())
|
|
|
|
|
|
|
|
Expect(gethStorage1).NotTo(Equal(gethStorage2))
|
2021-09-22 10:44:35 +00:00
|
|
|
Expect(gethStorage2).To(Equal(eth.EmptyNodeValue))
|
2021-09-06 14:44:06 +00:00
|
|
|
|
2023-04-14 06:26:46 +00:00
|
|
|
ipldStorage1, err := ipldClient.StorageAt(ctx, contract.Address, ercTotalSupplyIndex, big.NewInt(tx.BlockNumber-1))
|
2021-09-06 14:44:06 +00:00
|
|
|
Expect(err).ToNot(HaveOccurred())
|
2023-04-14 06:26:46 +00:00
|
|
|
ipldStorage2, err := ipldClient.StorageAt(ctx, contract.Address, ercTotalSupplyIndex, big.NewInt(tx.BlockNumber))
|
2021-09-06 14:44:06 +00:00
|
|
|
Expect(err).ToNot(HaveOccurred())
|
|
|
|
|
|
|
|
Expect(ipldStorage1).To(Equal(gethStorage1))
|
|
|
|
Expect(ipldStorage2).To(Equal(gethStorage2))
|
2021-09-23 10:36: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-09-23 10:36:09 +00:00
|
|
|
Expect(err).ToNot(HaveOccurred())
|
|
|
|
|
|
|
|
Expect(ipldStorage2).To(Equal(ipldStorage3))
|
2022-03-17 12:01:01 +00:00
|
|
|
|
|
|
|
// Check for SLV contract
|
2023-04-14 06:26:46 +00:00
|
|
|
gethStorage, err := gethClient.StorageAt(ctx, slvContract.Address, countAIndex, big.NewInt(slvTx.BlockNumber))
|
2022-03-17 12:01:01 +00:00
|
|
|
Expect(err).ToNot(HaveOccurred())
|
|
|
|
Expect(gethStorage).To(Equal(eth.EmptyNodeValue))
|
|
|
|
|
2023-04-14 06:26:46 +00:00
|
|
|
ipldStorage, err := ipldClient.StorageAt(ctx, slvContract.Address, countAIndex, big.NewInt(slvTx.BlockNumber))
|
2022-03-17 12:01:01 +00:00
|
|
|
Expect(err).ToNot(HaveOccurred())
|
|
|
|
Expect(ipldStorage).To(Equal(gethStorage))
|
2021-09-06 14:44:06 +00:00
|
|
|
})
|
2021-04-21 13:38:02 +00:00
|
|
|
})
|
|
|
|
|
2021-04-21 14:44:38 +00:00
|
|
|
Describe("eth call", func() {
|
2023-04-14 06:26:46 +00:00
|
|
|
var msg ethereum.CallMsg
|
|
|
|
|
2021-04-21 19:26:55 +00:00
|
|
|
BeforeEach(func() {
|
|
|
|
contract, contractErr = integration.DeployContract()
|
2021-04-21 14:44:38 +00:00
|
|
|
Expect(contractErr).ToNot(HaveOccurred())
|
|
|
|
|
2023-04-14 06:26:46 +00:00
|
|
|
msg = ethereum.CallMsg{
|
|
|
|
To: &contract.Address,
|
2021-04-21 14:44:38 +00:00
|
|
|
Data: common.Hex2Bytes("18160ddd"), // totalSupply()
|
|
|
|
}
|
2023-04-14 06:26:46 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
It("calls totalSupply() without block number", func() {
|
2021-04-21 14:44:38 +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))
|
|
|
|
Expect(err).ToNot(HaveOccurred())
|
2021-04-21 14:44:38 +00:00
|
|
|
|
2023-04-14 06:26:46 +00:00
|
|
|
gethTotalSupply := new(big.Int).SetBytes(gethResult)
|
|
|
|
Expect(gethTotalSupply).To(Equal(erc20TotalSupply))
|
|
|
|
|
|
|
|
ipldResult, err := ipldClient.CallContract(ctx, msg, big.NewInt(contract.BlockNumber))
|
|
|
|
Expect(err).ToNot(HaveOccurred())
|
|
|
|
|
|
|
|
Expect(gethResult).To(Equal(ipldResult))
|
|
|
|
})
|
|
|
|
|
|
|
|
It("calls totalSupply() with block hash", func() {
|
|
|
|
gethResult, err := gethClient.CallContractAtHash(ctx, msg, contract.BlockHash)
|
2021-04-21 14:44:38 +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.CallContractAtHash(ctx, msg, contract.BlockHash)
|
2021-04-21 14:44:38 +00:00
|
|
|
Expect(err).ToNot(HaveOccurred())
|
|
|
|
|
|
|
|
Expect(gethResult).To(Equal(ipldResult))
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2021-04-19 12:40:42 +00:00
|
|
|
Describe("Chain ID", func() {
|
2021-04-19 20:07:38 +00:00
|
|
|
It("Check chain id", func() {
|
2021-04-19 12:40:42 +00:00
|
|
|
gethChainId, err := gethClient.ChainID(ctx)
|
|
|
|
Expect(err).ToNot(HaveOccurred())
|
|
|
|
|
|
|
|
ipldChainId, err := ipldClient.ChainID(ctx)
|
|
|
|
Expect(err).ToNot(HaveOccurred())
|
|
|
|
|
|
|
|
Expect(gethChainId).To(Equal(ipldChainId))
|
|
|
|
})
|
|
|
|
})
|
2021-04-19 08:32:36 +00:00
|
|
|
})
|
2021-04-29 13:33:27 +00:00
|
|
|
|
|
|
|
func compareBlocks(block1 *types.Block, block2 *types.Block) {
|
2023-04-14 06:26:46 +00:00
|
|
|
GinkgoHelper()
|
2021-04-29 13:33:27 +00:00
|
|
|
Expect(block1.Header()).To(Equal(block2.Header()))
|
|
|
|
Expect(block1.Uncles()).To(Equal(block2.Uncles()))
|
|
|
|
|
|
|
|
txs1 := block1.Transactions()
|
|
|
|
txs2 := block2.Transactions()
|
|
|
|
|
|
|
|
Expect(len(txs1)).To(Equal(len(txs2)))
|
|
|
|
for i, tx := range txs1 {
|
|
|
|
compareTxs(tx, txs2[i])
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func compareTxs(tx1 *types.Transaction, tx2 *types.Transaction) {
|
2023-04-14 06:26:46 +00:00
|
|
|
GinkgoHelper()
|
2021-04-29 13:33:27 +00:00
|
|
|
Expect(tx1.Data()).To(Equal(tx2.Data()))
|
|
|
|
Expect(tx1.Hash()).To(Equal(tx2.Hash()))
|
|
|
|
Expect(tx1.Size()).To(Equal(tx2.Size()))
|
|
|
|
|
2023-04-14 06:26:46 +00:00
|
|
|
signer := types.NewLondonSigner(big.NewInt(testChainId))
|
2021-04-29 13:33:27 +00:00
|
|
|
|
|
|
|
gethSender, err := types.Sender(signer, tx1)
|
|
|
|
Expect(err).ToNot(HaveOccurred())
|
|
|
|
|
|
|
|
ipldSender, err := types.Sender(signer, tx2)
|
|
|
|
Expect(err).ToNot(HaveOccurred())
|
|
|
|
|
|
|
|
Expect(gethSender).To(Equal(ipldSender))
|
|
|
|
}
|