Browse Source

Ethclient: add readme & test env variables

feature/sql-semaphore1
laisolizq 3 years ago
committed by Eduard S
parent
commit
2e67008142
10 changed files with 134 additions and 47 deletions
  1. +7
    -0
      eth/.env.example
  2. +57
    -0
      eth/README.md
  3. +7
    -14
      eth/auction_test.go
  4. +1
    -1
      eth/contracts/README.md
  5. +1
    -1
      eth/contracts/auction/HermezAuctionProtocol.go
  6. +1
    -1
      eth/contracts/hermez/Hermez.go
  7. +57
    -29
      eth/main_test.go
  8. +1
    -1
      eth/rollup_test.go
  9. +1
    -0
      go.mod
  10. +1
    -0
      go.sum

+ 7
- 0
eth/.env.example

@ -0,0 +1,7 @@
GENESIS_BLOCK=97
AUCTION="0x038B86d9d8FAFdd0a02ebd1A476432877b0107C8"
AUCTION_TEST="0xEcc0a6dbC0bb4D51E4F84A315a9e5B0438cAD4f0"
TOKENHEZ="0xf4e77E5Da47AC3125140c470c71cBca77B5c638c"
HERMEZ="0xD6C850aeBFDC46D7F4c207e445cC0d6B0919BDBe"
WDELAYER="0x500D1d6A4c7D8Ae28240b47c8FCde034D827fD5e"
WDELAYER_TEST="0x1d80315fac6aBd3EfeEbE97dEc44461ba7556160"

+ 57
- 0
eth/README.md

@ -0,0 +1,57 @@
Test Ethclient - Contracts
## Contracts
The first step is to clone the github repository where the contracts are located:
`git clone https://github.com/hermeznetwork/contracts.git`
While the prepared deployment is not found to master, branch in repository must be changed:
`git checkout feature/ethclient-test-deployment`
Now, install the dependencies:
`npm i`
Go to where the deployment scripts for the test are found:
`cd scripts/ethclient-test-deployment`
Now, a bash script has to be run to do the deployment:
`./test-deployment`
This bash file follows these steps:
- `npx builder node`: a local blockchain to do our tests
- `npx buidler run --network localhost test-deployment.js`: run the deployment on the local blockchain
An output file necessary for the next step is obtained: `deploy-output`.
> The files that find in `/eth/contracts` must be obtained from the same contract that we deploy in this step
## Ethclient Test
Different environment variables are necessary to run this test.
They must be taken from the output file of the previous step.
They can be provided by file called `.env`:
```
GENESIS_BLOCK=97
AUCTION="0x038B86d9d8FAFdd0a02ebd1A476432877b0107C8"
AUCTION_TEST="0xEcc0a6dbC0bb4D51E4F84A315a9e5B0438cAD4f0"
TOKENHEZ="0xf4e77E5Da47AC3125140c470c71cBca77B5c638c"
HERMEZ="0xD6C850aeBFDC46D7F4c207e445cC0d6B0919BDBe"
WDELAYER="0x500D1d6A4c7D8Ae28240b47c8FCde034D827fD5e"
WDELAYER_TEST="0x1d80315fac6aBd3EfeEbE97dEc44461ba7556160"
```
> An example is found in `/etc/.env.example`
And then run test:
`INTEGRATION=1 go test`
Or they can be provided as a parameter in the command that runs the test:
`INTEGRATION=1 GENESIS_BLOCK=97 AUCTION="0x038B86d9d8FAFdd0a02ebd1A476432877b0107C8" AUCTION_TEST="0xEcc0a6dbC0bb4D51E4F84A315a9e5B0438cAD4f0" TOKENHEZ="0xf4e77E5Da47AC3125140c470c71cBca77B5c638c" HERMEZ="0xD6C850aeBFDC46D7F4c207e445cC0d6B0919BDBe" WDELAYER="0x500D1d6A4c7D8Ae28240b47c8FCde034D827fD5e" WDELAYER_TEST="0x1d80315fac6aBd3EfeEbE97dEc44461ba7556160" go test`

+ 7
- 14
eth/auction_test.go

@ -13,20 +13,13 @@ const openAuctionSlotsConst = uint16(4320)
const closedAuctionSlotsConst = uint16(2)
const outbiddingConst = uint16(1000)
const currentSlotConst = 0
const BLOCKSPERSLOT = uint8(40)
const minBidStr = "10000000000000000000"
const URL = "http://localhost:3000"
var allocationRatioConst [3]uint16 = [3]uint16{4000, 4000, 2000}
var auctionClientTest *AuctionClient
//var genesisBlock = 93
var genesisBlock = 97
var minBidStr = "10000000000000000000"
var URL = "http://localhost:3000"
// var newURL = "http://localhost:3002"
var BLOCKSPERSLOT = uint8(40)
func TestAuctionGetCurrentSlotNumber(t *testing.T) {
currentSlot, err := auctionClientTest.AuctionGetCurrentSlotNumber()
require.Nil(t, err)
@ -41,7 +34,7 @@ func TestAuctionConstants(t *testing.T) {
auctionConstants, err := auctionClientTest.AuctionConstants()
require.Nil(t, err)
assert.Equal(t, auctionConstants.BlocksPerSlot, BLOCKSPERSLOT)
assert.Equal(t, auctionConstants.GenesisBlockNum, int64(genesisBlock))
assert.Equal(t, auctionConstants.GenesisBlockNum, genesisBlock)
assert.Equal(t, auctionConstants.HermezRollup, hermezRollupAddressTestConst)
assert.Equal(t, auctionConstants.InitialMinimalBidding, INITMINBID)
assert.Equal(t, auctionConstants.TokenHEZ, tokenHEZAddressConst)
@ -284,7 +277,7 @@ func TestAuctionBid(t *testing.T) {
func TestAuctionGetSlotNumber(t *testing.T) {
slotConst := 4
blockNum := int(BLOCKSPERSLOT)*slotConst + genesisBlock
blockNum := int(BLOCKSPERSLOT)*slotConst + int(genesisBlock)
slot, err := auctionClientTest.AuctionGetSlotNumber(int64(blockNum))
require.Nil(t, err)
@ -293,7 +286,7 @@ func TestAuctionGetSlotNumber(t *testing.T) {
func TestAuctionCanForge(t *testing.T) {
slotConst := 4
blockNum := int(BLOCKSPERSLOT)*slotConst + genesisBlock
blockNum := int(BLOCKSPERSLOT)*slotConst + int(genesisBlock)
canForge, err := auctionClientTest.AuctionCanForge(governanceAddressConst, int64(blockNum))
require.Nil(t, err)
@ -351,7 +344,7 @@ func TestAuctionForge(t *testing.T) {
auctionClientTestHermez, err := NewAuctionClient(ethereumClientHermez, auctionTestAddressConst, tokenHEZ)
require.Nil(t, err)
slotConst := 4
blockNum := int64(int(BLOCKSPERSLOT)*slotConst + genesisBlock)
blockNum := int64(int(BLOCKSPERSLOT)*slotConst + int(genesisBlock))
currentBlockNum, _ := auctionClientTestHermez.client.EthCurrentBlock()
blocksToAdd := blockNum - currentBlockNum
addBlocks(blocksToAdd, ethClientDialURL)

+ 1
- 1
eth/contracts/README.md

@ -10,9 +10,9 @@ abigen --abi=HEZ.abi --bin=HEZ.bin --pkg=HEZ --out=HEZ.go
```
You must compile the contracts to get the `.bin` and `.abi` files. The contracts used are in the repo: https://github.com/hermeznetwork/contracts
Branch: `RemoveERC777`
Specifically they have been processed in the commit with hash: `7574ba47fd3d7dab2653a22f57b15c69280350dc`
Versions:
```
$ abigen --version

+ 1
- 1
eth/contracts/auction/HermezAuctionProtocol.go
File diff suppressed because it is too large
View File


+ 1
- 1
eth/contracts/hermez/Hermez.go
File diff suppressed because it is too large
View File


+ 57
- 29
eth/main_test.go

@ -1,9 +1,11 @@
package eth
import (
"fmt"
"io/ioutil"
"math/big"
"os"
"strconv"
"testing"
"github.com/ethereum/go-ethereum/accounts"
@ -11,38 +13,32 @@ import (
ethCommon "github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/ethclient"
"github.com/joho/godotenv"
)
/*var donationAddressStr = os.Getenv("DONATION_ADDRESS")
var bootCoordinatorStr = os.Getenv("BOOT_COORDINATOR_ADDRESS")
var auctionAddressStr = os.Getenv("AUCTION_ADDRESS")
var tokenHezStr = os.Getenv("TOKEN_ADDRESS")
var hermezStr = os.Getenv("HERMEZ_ADDRESS")
var governanceAddressStr = os.Getenv("GOV_ADDRESS")
var governancePrivateKey = os.Getenv("GOV_PK")
var ethClientDialURL = os.Getenv("ETHCLIENT_DIAL_URL")*/
var ethClientDialURL = "http://localhost:8545"
var password = "pass"
var deadline, _ = new(big.Int).SetString("ffffffffffffffffffffffffffffffff", 16)
var ethClientDialURLConst = "http://localhost:8545"
var passwordConst = "pass"
var deadlineConst, _ = new(big.Int).SetString("ffffffffffffffffffffffffffffffff", 16)
var errEnvVar = fmt.Errorf("Some environment variable is missing")
// Smart Contract Addresses
var (
auctionAddressStr = "0x038B86d9d8FAFdd0a02ebd1A476432877b0107C8"
auctionAddressConst = ethCommon.HexToAddress(auctionAddressStr)
auctionTestAddressStr = "0xEcc0a6dbC0bb4D51E4F84A315a9e5B0438cAD4f0"
auctionTestAddressConst = ethCommon.HexToAddress(auctionTestAddressStr)
password string
ethClientDialURL string
deadline *big.Int
genesisBlock int64
auctionAddressConst ethCommon.Address
auctionTestAddressConst ethCommon.Address
tokenHEZAddressConst ethCommon.Address
hermezRollupAddressConst ethCommon.Address
wdelayerAddressConst ethCommon.Address
wdelayerTestAddressConst ethCommon.Address
tokenHEZ TokenConfig
donationAddressStr = "0x6c365935CA8710200C7595F0a72EB6023A7706Cd"
donationAddressConst = ethCommon.HexToAddress(donationAddressStr)
bootCoordinatorAddressStr = "0xc783df8a850f42e7f7e57013759c285caa701eb6"
bootCoordinatorAddressConst = ethCommon.HexToAddress(bootCoordinatorAddressStr)
tokenHEZAddressStr = "0xf4e77E5Da47AC3125140c470c71cBca77B5c638c" //nolint:gosec
tokenHEZAddressConst = ethCommon.HexToAddress(tokenHEZAddressStr)
hermezRollupAddressStr = "0xD6C850aeBFDC46D7F4c207e445cC0d6B0919BDBe"
hermezRollupAddressConst = ethCommon.HexToAddress(hermezRollupAddressStr)
wdelayerAddressStr = "0x500D1d6A4c7D8Ae28240b47c8FCde034D827fD5e"
wdelayerAddressConst = ethCommon.HexToAddress(wdelayerAddressStr)
wdelayerTestAddressStr = "0x1d80315fac6aBd3EfeEbE97dEc44461ba7556160"
wdelayerTestAddressConst = ethCommon.HexToAddress(wdelayerTestAddressStr)
safetyAddressStr = "0xE5904695748fe4A84b40b3fc79De2277660BD1D3"
safetyAddressConst = ethCommon.HexToAddress(safetyAddressStr)
)
@ -78,11 +74,6 @@ var (
hermezRollupAddressTestConst = ethCommon.HexToAddress(hermezRollupTestAddressStr)
)
var tokenHEZ = TokenConfig{
Address: tokenHEZAddressConst,
Name: "Hermez Network Token",
}
var (
accountGov *accounts.Account
accountKep *accounts.Account
@ -117,10 +108,48 @@ func addKey(ks *keystore.KeyStore, skHex string) *accounts.Account {
return &account
}
func getEnvVariables() {
err := godotenv.Load()
if err != nil {
fmt.Println("Variables loaded from command")
} else {
fmt.Println("Variables loaded from .env file")
}
var auctionAddressStr = os.Getenv("AUCTION")
var auctionTestAddressStr = os.Getenv("AUCTION_TEST")
var tokenHEZAddressStr = os.Getenv("TOKENHEZ")
var hermezRollupAddressStr = os.Getenv("HERMEZ")
var wdelayerAddressStr = os.Getenv("WDELAYER")
var wdelayerTestAddressStr = os.Getenv("WDELAYER_TEST")
genesisBlockEnv := os.Getenv("GENESIS_BLOCK")
genesisBlock, err = strconv.ParseInt(genesisBlockEnv, 10, 64)
if err != nil {
panic(errEnvVar)
}
if auctionAddressStr == "" || auctionTestAddressStr == "" || tokenHEZAddressStr == "" || hermezRollupAddressStr == "" || wdelayerAddressStr == "" || wdelayerTestAddressStr == "" || genesisBlockEnv == "" {
panic(errEnvVar)
}
ethClientDialURL = ethClientDialURLConst
password = passwordConst
deadline = deadlineConst
auctionAddressConst = ethCommon.HexToAddress(auctionAddressStr)
auctionTestAddressConst = ethCommon.HexToAddress(auctionTestAddressStr)
tokenHEZAddressConst = ethCommon.HexToAddress(tokenHEZAddressStr)
hermezRollupAddressConst = ethCommon.HexToAddress(hermezRollupAddressStr)
wdelayerAddressConst = ethCommon.HexToAddress(wdelayerAddressStr)
wdelayerTestAddressConst = ethCommon.HexToAddress(wdelayerTestAddressStr)
tokenHEZ = TokenConfig{
Address: tokenHEZAddressConst,
Name: "Hermez Network Token",
}
}
func TestMain(m *testing.M) {
exitVal := 0
if os.Getenv("INTEGRATION") != "" {
getEnvVariables()
dir, err := ioutil.TempDir("", "tmpks")
if err != nil {
panic(err)
@ -147,7 +176,6 @@ func TestMain(m *testing.M) {
}
// Controllable Governance Address
ethereumClientGov := NewEthereumClient(ethClient, accountGov, ks, nil)
auctionClient, err = NewAuctionClient(ethereumClientGov, auctionAddressConst, tokenHEZ)
if err != nil {

+ 1
- 1
eth/rollup_test.go

@ -105,7 +105,7 @@ func TestRollupForgeBatch(t *testing.T) {
require.Nil(t, err)
// Add Blocks
blockNum := int64(int(BLOCKSPERSLOT)*int(currentSlot+4) + genesisBlock)
blockNum := int64(int(BLOCKSPERSLOT)*int(currentSlot+4) + int(genesisBlock))
currentBlockNum, _ := auctionClient.client.EthCurrentBlock()
blocksToAdd := blockNum - currentBlockNum
addBlocks(blocksToAdd, ethClientDialURL)

+ 1
- 0
go.mod

@ -15,6 +15,7 @@ require (
github.com/iden3/go-merkletree v0.0.0-20200902123354-eeb949f8c334
github.com/jinzhu/copier v0.0.0-20190924061706-b57f9002281a
github.com/jmoiron/sqlx v1.2.0
github.com/joho/godotenv v1.3.0
github.com/lib/pq v1.8.0
github.com/mitchellh/copystructure v1.0.0
github.com/rogpeppe/go-internal v1.6.1 // indirect

+ 1
- 0
go.sum

@ -324,6 +324,7 @@ github.com/jinzhu/copier v0.0.0-20190924061706-b57f9002281a/go.mod h1:yL958EeXv8
github.com/jmespath/go-jmespath v0.0.0-20180206201540-c2b33e8439af/go.mod h1:Nht3zPeWKUH0NzdCt2Blrr5ys8VGpn0CEB0cQHVjt7k=
github.com/jmoiron/sqlx v1.2.0 h1:41Ip0zITnmWNR/vHV+S4m+VoUivnWY5E4OJfLZjCJMA=
github.com/jmoiron/sqlx v1.2.0/go.mod h1:1FEQNm3xlJgrMD+FBdI9+xvCksHtbpVBBw5dYhBSsks=
github.com/joho/godotenv v1.3.0 h1:Zjp+RcGpHhGlrMbJzXTrZZPrWj+1vfm90La1wgB6Bhc=
github.com/joho/godotenv v1.3.0/go.mod h1:7hK45KPybAkOC6peb+G5yklZfMxEjkZhHbwpqxOKXbg=
github.com/jonboulle/clockwork v0.1.0/go.mod h1:Ii8DK3G1RaLaWxj9trq07+26W01tbo22gdxWY5EU2bo=
github.com/jrick/logrotate v1.0.0/go.mod h1:LNinyqDIJnpAur+b8yyulnQw/wDuN1+BYKlTRt3OuAQ=

Loading…
Cancel
Save