Feature/update go geth sharding (#13)

* Upgrade Geth, Go and add CICD

* update ipld-eth-server version

* Track validation progress on a channel

* Add integration tests

* Setup validator config and update instructions to run tests locally

* Update readme and tests

* Update test to use v4 Infrastructure

* Inlcude the env file

* Fix config file write

* Update DB configuration

Co-authored-by: prathamesh0 <prathamesh.musale0@gmail.com>
Co-authored-by: Ashwin Phatak <ashwinpphatak@gmail.com>
This commit is contained in:
Abdul Rabbani
2022-06-03 09:28:02 -04:00
committed by GitHub
co-authored by prathamesh Ashwin Phatak
parent cc935dc97b
commit d111dd85db
15 changed files with 428 additions and 360 deletions
+7 -3
View File
@@ -6,18 +6,18 @@
- Clone [stack-orchestrator](https://github.com/vulcanize/stack-orchestrator) and [go-ethereum](https://github.com/vulcanize/go-ethereum) repositories.
- Checkout [v4 release](https://github.com/vulcanize/go-ethereum/releases/tag/v1.10.17-statediff-4.0.1-alpha) in go-ethereum repo.
- Checkout [v4 release](https://github.com/vulcanize/go-ethereum/releases/tag/v1.10.18-statediff-4.0.2-alpha) in go-ethereum repo.
```bash
# In go-ethereum repo.
git checkout v1.10.17-statediff-4.0.1-alpha
git checkout v1.10.18-statediff-4.0.2-alpha
```
- Checkout working commit in stack-orchestrator repo.
```bash
# In stack-orchestrator repo.
git checkout 42af57a2963bb6ca55fb5fcb16ed75b39fae60f9
git checkout 418957a1f745c921b21286c13bb033f922a91ae9
```
## Run
@@ -55,6 +55,10 @@
vulcanize_test_contract=~/ipld-eth-db-validator/test/contract
db_write=true
ipld_eth_server_db_dependency=access-node
go_ethereum_db_dependency=access-node
connecting_db_name=vulcanize_testing_v4
```
- Run stack-orchestrator:
+29
View File
@@ -0,0 +1,29 @@
// SPDX-License-Identifier: AGPL-3.0
pragma solidity ^0.8.0;
contract Test {
address payable owner;
modifier onlyOwner {
require(
msg.sender == owner,
"Only owner can call this function."
);
_;
}
uint256[100] data;
constructor() {
owner = payable(msg.sender);
data = [1];
}
function Put(uint256 addr, uint256 value) public {
data[addr] = value;
}
function close() public onlyOwner {
selfdestruct(owner);
}
}
+44 -1
View File
@@ -63,6 +63,49 @@ fastify.get('/v1/sendEth', async (req, reply) => {
}
});
fastify.get('/v1/deployTestContract', async (req, reply) => {
const testContract = await hre.ethers.getContractFactory("Test");
const test = await testContract.deploy();
await test.deployed();
return {
address: test.address,
txHash: test.deployTransaction.hash,
blockNumber: test.deployTransaction.blockNumber,
blockHash: test.deployTransaction.blockHash,
}
});
fastify.get('/v1/putTestValue', async (req, reply) => {
const addr = req.query.addr;
const index = req.query.index;
const value = req.query.value;
const testContract = await hre.ethers.getContractFactory("Test");
const test = await testContract.attach(addr);
const tx = await test.Put(index, value);
const receipt = await tx.wait();
return {
blockNumber: receipt.blockNumber,
}
});
fastify.get('/v1/destroyTestContract', async (req, reply) => {
const addr = req.query.addr;
const testContract = await hre.ethers.getContractFactory("Test");
const test = await testContract.attach(addr);
await test.destroy();
const blockNum = await hre.ethers.provider.getBlockNumber()
return {
blockNumber: blockNum,
}
})
async function main() {
try {
await fastify.listen(3000, '0.0.0.0');
@@ -72,4 +115,4 @@ async function main() {
}
}
main();
main();
+54
View File
@@ -0,0 +1,54 @@
package integration
import (
"encoding/json"
"fmt"
"net/http"
ethServerIntegration "github.com/vulcanize/ipld-eth-server/v4/test"
)
type PutResult struct {
BlockNumber int64 `json:"blockNumber"`
}
const srvUrl = "http://localhost:3000"
func DeployTestContract() (*ethServerIntegration.ContractDeployed, error) {
ethServerIntegration.DeployContract()
res, err := http.Get(fmt.Sprintf("%s/v1/deployTestContract", srvUrl))
if err != nil {
return nil, err
}
defer res.Body.Close()
var contract ethServerIntegration.ContractDeployed
decoder := json.NewDecoder(res.Body)
return &contract, decoder.Decode(&contract)
}
func PutTestValue(addr string, index, value int) (*PutResult, error) {
res, err := http.Get(fmt.Sprintf("%s/v1/putTestValue?addr=%s&index=%d&value=%d", srvUrl, addr, index, value))
if err != nil {
return nil, err
}
var blockNumber PutResult
decoder := json.NewDecoder(res.Body)
return &blockNumber, decoder.Decode(&blockNumber)
}
func DestroyTestContract(addr string) (*ethServerIntegration.ContractDestroyed, error) {
res, err := http.Get(fmt.Sprintf("%s/v1/destroyTestContract?addr=%s", srvUrl, addr))
if err != nil {
return nil, err
}
defer res.Body.Close()
var data ethServerIntegration.ContractDestroyed
decoder := json.NewDecoder(res.Body)
return &data, decoder.Decode(&data)
}
+76 -14
View File
@@ -2,45 +2,107 @@ package integration_test
import (
"context"
"sync"
"time"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
"github.com/vulcanize/ipld-eth-db-validator/pkg/validator"
integration "github.com/vulcanize/ipld-eth-db-validator/test"
"github.com/vulcanize/ipld-eth-server/v4/pkg/shared"
integration "github.com/vulcanize/ipld-eth-server/v4/test"
ethServerIntegration "github.com/vulcanize/ipld-eth-server/v4/test"
)
const (
blockNum = 1
trail = 0
validatorSleepInterval = uint(5)
)
var (
testAddresses = []string{
"0x1111111111111111111111111111111111111112",
"0x1ca7c995f8eF0A2989BbcE08D5B7Efe50A584aa1",
"0x9a4b666af23a2cdb4e5538e1d222a445aeb82134",
"0xF7C7AEaECD2349b129d5d15790241c32eeE4607B",
"0x992b6E9BFCA1F7b0797Cee10b0170E536EAd3532",
"0x29ed93a7454Bc17a8D4A24D0627009eE0849B990",
"0x66E3dCA826b04B5d4988F7a37c91c9b1041e579D",
"0x96288939Ac7048c27E0E087b02bDaad3cd61b37b",
"0xD354280BCd771541c935b15bc04342c26086FE9B",
"0x7f887e25688c274E77b8DeB3286A55129B55AF14",
}
)
var _ = Describe("Integration test", func() {
ctx := context.Background()
var contract *integration.ContractDeployed
var contractErr error
sleepInterval := 5 * time.Second
var contract *ethServerIntegration.ContractDeployed
var err error
sleepInterval := 2 * time.Second
timeout := 4 * time.Second
db := shared.SetupDB()
cfg := validator.Config{
DB: db,
BlockNum: blockNum,
Trail: trail,
SleepInterval: validatorSleepInterval,
ChainCfg: validator.IntegrationTestChainConfig,
}
validationProgressChan := make(chan uint64)
service := validator.NewService(&cfg, validationProgressChan)
wg := new(sync.WaitGroup)
It("test init", func() {
wg.Add(1)
go service.Start(ctx, wg)
// Deploy a dummy contract as the first contract might get deployed at block number 0
_, _ = ethServerIntegration.DeployContract()
time.Sleep(sleepInterval)
})
defer It("test teardown", func() {
service.Stop()
wg.Wait()
Expect(validationProgressChan).To(BeClosed())
})
Describe("Validate state", func() {
BeforeEach(func() {
// Deploy a dummy contract as the first contract might get deployed at block number 0
_, _ = integration.DeployContract()
It("performs validation on contract deployment", func() {
contract, err = integration.DeployTestContract()
Expect(err).ToNot(HaveOccurred())
time.Sleep(sleepInterval)
contract, contractErr = integration.DeployContract()
time.Sleep(sleepInterval)
Expect(validationProgressChan).ToNot(BeClosed())
Eventually(validationProgressChan, timeout).Should(Receive(Equal(uint64(contract.BlockNumber))))
})
It("Validate state root", func() {
Expect(contractErr).ToNot(HaveOccurred())
It("performs validation on contract transactions", func() {
for i := 0; i < 10; i++ {
res, txErr := integration.PutTestValue(contract.Address, i, i)
Expect(txErr).ToNot(HaveOccurred())
time.Sleep(sleepInterval)
db := shared.SetupDB()
srvc := validator.NewService(db, uint64(contract.BlockNumber), trail, validatorSleepInterval, validator.IntegrationTestChainConfig)
srvc.Start(ctx, nil)
Expect(validationProgressChan).ToNot(BeClosed())
Eventually(validationProgressChan, timeout).Should(Receive(Equal(uint64(res.BlockNumber))))
}
})
It("performs validation on eth transfer transactions", func() {
for _, address := range testAddresses {
tx, txErr := ethServerIntegration.SendEth(address, "0.01")
Expect(txErr).ToNot(HaveOccurred())
time.Sleep(sleepInterval)
Expect(validationProgressChan).ToNot(BeClosed())
Eventually(validationProgressChan, timeout).Should(Receive(Equal(uint64(tx.BlockNumber))))
}
})
})
})