Update ethclient & L1CoordinatorTx

This commit is contained in:
laisolizq
2020-11-20 13:45:22 +01:00
parent bf88eb60b8
commit f775af8890
10 changed files with 754 additions and 43 deletions

View File

@@ -8,7 +8,7 @@ The first step is to clone the github repository where the contracts are located
While the prepared deployment is not found to master, branch in repository must be changed:
`git checkout feature/ethclient-test-deployment-ganache` (tested with commit `f62c768bd4817921872666b3644403a119e28248`)
`git checkout feature/newDeploymentScript-ethclient` (tested with commit `af4c93916d6cd93d866c121cc63b6a6794f649b2`)
Now, install the dependencies:

View File

@@ -3,12 +3,15 @@ package eth
import (
"testing"
"github.com/ethereum/go-ethereum/ethclient"
"github.com/stretchr/testify/require"
)
func TestClientInterface(t *testing.T) {
ethClient, err := ethclient.Dial(ethClientDialURL)
require.Nil(t, err)
var c ClientInterface
client, _ := NewClient(nil, nil, nil, &ClientConfig{})
client, _ := NewClient(ethClient, nil, nil, &ClientConfig{})
c = client
require.NotNil(t, c)
}

View File

@@ -10,8 +10,8 @@ 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: `2a1cfccfba6770c1077ecea983d2c743dc4a1e93`
Branch: `feature/newDeploymentScript`
Specifically they have been processed in the commit with hash: `4489f8e7fe4dd17cf22f1e96741b09bdf81946d8`
Versions:
```

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@@ -190,6 +190,7 @@ type RollupInterface interface {
// RollupClient is the implementation of the interface to the Rollup Smart Contract in ethereum.
type RollupClient struct {
client *EthereumClient
chainID *big.Int
address ethCommon.Address
tokenHEZCfg TokenConfig
hermez *Hermez.Hermez
@@ -211,8 +212,13 @@ func NewRollupClient(client *EthereumClient, address ethCommon.Address, tokenHEZ
if err != nil {
return nil, err
}
chainID, err := client.client.ChainID(context.Background())
if err != nil {
return nil, err
}
return &RollupClient{
client: client,
chainID: chainID,
address: address,
tokenHEZCfg: tokenHEZCfg,
hermez: hermez,
@@ -290,8 +296,7 @@ func (c *RollupClient) RollupAddToken(tokenAddress ethCommon.Address, feeAddToke
}
tokenName := c.tokenHEZCfg.Name
tokenAddr := c.tokenHEZCfg.Address
chainid, _ := c.client.Client().ChainID(context.Background())
digest, _ := createPermitDigest(tokenAddr, owner, spender, chainid, feeAddToken, nonce, deadline, tokenName)
digest, _ := createPermitDigest(tokenAddr, owner, spender, c.chainID, feeAddToken, nonce, deadline, tokenName)
signature, _ := c.client.ks.SignHash(*c.client.account, digest)
permit := createPermit(owner, spender, feeAddToken, deadline, digest, signature)
@@ -387,8 +392,7 @@ func (c *RollupClient) RollupL1UserTxERC20Permit(fromBJJ *babyjub.PublicKey, fro
}
tokenName := c.tokenHEZCfg.Name
tokenAddr := c.tokenHEZCfg.Address
chainid, _ := c.client.Client().ChainID(context.Background())
digest, _ := createPermitDigest(tokenAddr, owner, spender, chainid, amount, nonce, deadline, tokenName)
digest, _ := createPermitDigest(tokenAddr, owner, spender, c.chainID, amount, nonce, deadline, tokenName)
signature, _ := c.client.ks.SignHash(*c.client.account, digest)
permit := createPermit(owner, spender, amount, deadline, digest, signature)
return c.hermez.AddL1Transaction(auth, babyPubKey, fromIdxBig, uint16(loadAmountF),
@@ -601,6 +605,7 @@ func (c *RollupClient) RollupForgeBatchArgs(ethTxHash ethCommon.Hash) (*RollupFo
return nil, nil, err
}
txData := tx.Data()
method, err := c.contractAbi.MethodById(txData[:4])
if err != nil {
return nil, nil, err
@@ -641,7 +646,7 @@ func (c *RollupClient) RollupForgeBatchArgs(ethTxHash ethCommon.Hash) (*RollupFo
signature = append(signature, r[:]...)
signature = append(signature, s[:]...)
signature = append(signature, v)
l1Tx, err := common.L1CoordinatorTxFromBytes(bytesL1Coordinator)
l1Tx, err := common.L1CoordinatorTxFromBytes(bytesL1Coordinator, c.chainID, c.address)
if err != nil {
return nil, nil, err
}

View File

@@ -1,6 +1,7 @@
package eth
import (
"context"
"crypto/ecdsa"
"encoding/binary"
"encoding/hex"
@@ -86,6 +87,7 @@ func TestRollupAddToken(t *testing.T) {
}
func TestRollupForgeBatch(t *testing.T) {
chainid, _ := auctionClient.client.Client().ChainID(context.Background())
// Register Coordinator
forgerAddress := governanceAddressConst
_, err := auctionClient.AuctionSetCoordinator(forgerAddress, URL)
@@ -125,7 +127,7 @@ func TestRollupForgeBatch(t *testing.T) {
signature = append(signature, r[:]...)
signature = append(signature, s[:]...)
signature = append(signature, v)
l1Tx, err := common.L1CoordinatorTxFromBytes(bytesL1Coordinator)
l1Tx, err := common.L1CoordinatorTxFromBytes(bytesL1Coordinator, chainid, rollupClient.address)
require.Nil(t, err)
args.L1CoordinatorTxs = append(args.L1CoordinatorTxs, *l1Tx)
args.L1CoordinatorTxsAuths = append(args.L1CoordinatorTxsAuths, signature)