mirror of
https://github.com/arnaucube/hermez-node.git
synced 2026-02-07 11:26:44 +01:00
Update test ethclient, rename rollup var
This commit is contained in:
@@ -335,13 +335,13 @@ type RollupInterface interface {
|
|||||||
type RollupClient struct {
|
type RollupClient struct {
|
||||||
client *EthereumClient
|
client *EthereumClient
|
||||||
address ethCommon.Address
|
address ethCommon.Address
|
||||||
tokenAddress ethCommon.Address
|
tokenHEZAddress ethCommon.Address
|
||||||
gasLimit uint64
|
gasLimit uint64
|
||||||
contractAbi abi.ABI
|
contractAbi abi.ABI
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewRollupClient creates a new RollupClient
|
// NewRollupClient creates a new RollupClient
|
||||||
func NewRollupClient(client *EthereumClient, address ethCommon.Address, tokenAddress ethCommon.Address) (*RollupClient, error) {
|
func NewRollupClient(client *EthereumClient, address ethCommon.Address, tokenHEZAddress ethCommon.Address) (*RollupClient, error) {
|
||||||
contractAbi, err := abi.JSON(strings.NewReader(string(Hermez.HermezABI)))
|
contractAbi, err := abi.JSON(strings.NewReader(string(Hermez.HermezABI)))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@@ -349,7 +349,7 @@ func NewRollupClient(client *EthereumClient, address ethCommon.Address, tokenAdd
|
|||||||
return &RollupClient{
|
return &RollupClient{
|
||||||
client: client,
|
client: client,
|
||||||
address: address,
|
address: address,
|
||||||
tokenAddress: tokenAddress,
|
tokenHEZAddress: tokenHEZAddress,
|
||||||
gasLimit: 1000000, //nolint:gomnd
|
gasLimit: 1000000, //nolint:gomnd
|
||||||
contractAbi: contractAbi,
|
contractAbi: contractAbi,
|
||||||
}, nil
|
}, nil
|
||||||
@@ -371,7 +371,7 @@ func (c *RollupClient) RollupForgeBatch(args *RollupForgeBatchArgs) (*types.Tran
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
nLevels := rollupConst.Verifiers[args.VerifierIdx].NLevels
|
nLevels := rollupConst.Verifiers[args.VerifierIdx].NLevels
|
||||||
lenBytes := nLevels / 8
|
lenBytes := nLevels / 8 //nolint:gomnd
|
||||||
newLastIdx := big.NewInt(int64(args.NewLastIdx))
|
newLastIdx := big.NewInt(int64(args.NewLastIdx))
|
||||||
var l1CoordinatorBytes []byte
|
var l1CoordinatorBytes []byte
|
||||||
for i := 0; i < len(args.L1CoordinatorTxs); i++ {
|
for i := 0; i < len(args.L1CoordinatorTxs); i++ {
|
||||||
@@ -408,14 +408,16 @@ func (c *RollupClient) RollupForgeBatch(args *RollupForgeBatchArgs) (*types.Tran
|
|||||||
return tx, nil
|
return tx, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// RollupAddToken is the interface to call the smart contract function
|
// RollupAddToken is the interface to call the smart contract function.
|
||||||
|
// `feeAddToken` is the amount of HEZ tokens that will be paid to add the
|
||||||
|
// token. `feeAddToken` must match the public value of the smart contract.
|
||||||
func (c *RollupClient) RollupAddToken(tokenAddress ethCommon.Address, feeAddToken *big.Int) (*types.Transaction, error) {
|
func (c *RollupClient) RollupAddToken(tokenAddress ethCommon.Address, feeAddToken *big.Int) (*types.Transaction, error) {
|
||||||
var tx *types.Transaction
|
var tx *types.Transaction
|
||||||
var err error
|
var err error
|
||||||
if tx, err = c.client.CallAuth(
|
if tx, err = c.client.CallAuth(
|
||||||
c.gasLimit,
|
c.gasLimit,
|
||||||
func(ec *ethclient.Client, auth *bind.TransactOpts) (*types.Transaction, error) {
|
func(ec *ethclient.Client, auth *bind.TransactOpts) (*types.Transaction, error) {
|
||||||
tokens, err := ERC777.NewERC777(c.tokenAddress, ec)
|
tokens, err := ERC777.NewERC777(c.tokenHEZAddress, ec)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -35,8 +35,7 @@ func TestRollupConstants(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestAddToken(t *testing.T) {
|
func TestAddToken(t *testing.T) {
|
||||||
var feeAddToken = new(big.Int)
|
feeAddToken := big.NewInt(10)
|
||||||
feeAddToken = big.NewInt(10)
|
|
||||||
// Addtoken
|
// Addtoken
|
||||||
_, err := rollupClient.RollupAddToken(tokenERC777AddressConst, feeAddToken)
|
_, err := rollupClient.RollupAddToken(tokenERC777AddressConst, feeAddToken)
|
||||||
require.Nil(t, err)
|
require.Nil(t, err)
|
||||||
|
|||||||
@@ -74,7 +74,8 @@ D (3): 15
|
|||||||
// require.Greater(t, len(tokens), 0)
|
// require.Greater(t, len(tokens), 0)
|
||||||
|
|
||||||
for i := 1; i <= 3; i++ {
|
for i := 1; i <= 3; i++ {
|
||||||
_, err := client.RollupAddToken(ethCommon.BigToAddress(big.NewInt(int64(i * 10000))))
|
_, err := client.RollupAddToken(ethCommon.BigToAddress(big.NewInt(int64(i*10000))),
|
||||||
|
clientSetup.RollupVariables.FeeAddToken)
|
||||||
require.Nil(t, err)
|
require.Nil(t, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -690,7 +690,7 @@ func (c *Client) addBatch(args *eth.RollupForgeBatchArgs) (*types.Transaction, e
|
|||||||
}
|
}
|
||||||
|
|
||||||
// RollupAddToken is the interface to call the smart contract function
|
// RollupAddToken is the interface to call the smart contract function
|
||||||
func (c *Client) RollupAddToken(tokenAddress ethCommon.Address) (tx *types.Transaction, err error) {
|
func (c *Client) RollupAddToken(tokenAddress ethCommon.Address, feeAddToken *big.Int) (tx *types.Transaction, err error) {
|
||||||
c.rw.Lock()
|
c.rw.Lock()
|
||||||
defer c.rw.Unlock()
|
defer c.rw.Unlock()
|
||||||
cpy := c.nextBlock().copy()
|
cpy := c.nextBlock().copy()
|
||||||
@@ -704,6 +704,9 @@ func (c *Client) RollupAddToken(tokenAddress ethCommon.Address) (tx *types.Trans
|
|||||||
if _, ok := r.State.TokenMap[tokenAddress]; ok {
|
if _, ok := r.State.TokenMap[tokenAddress]; ok {
|
||||||
return nil, fmt.Errorf("Token %v already registered", tokenAddress)
|
return nil, fmt.Errorf("Token %v already registered", tokenAddress)
|
||||||
}
|
}
|
||||||
|
if feeAddToken.Cmp(r.Vars.FeeAddToken) != 0 {
|
||||||
|
return nil, fmt.Errorf("Expected fee: %v but got: %v", r.Vars.FeeAddToken, feeAddToken)
|
||||||
|
}
|
||||||
|
|
||||||
r.State.TokenMap[tokenAddress] = true
|
r.State.TokenMap[tokenAddress] = true
|
||||||
r.State.TokenList = append(r.State.TokenList, tokenAddress)
|
r.State.TokenList = append(r.State.TokenList, tokenAddress)
|
||||||
|
|||||||
@@ -143,7 +143,7 @@ func TestClientRollup(t *testing.T) {
|
|||||||
|
|
||||||
// Add a token
|
// Add a token
|
||||||
|
|
||||||
tx, err := c.RollupAddToken(token1Addr)
|
tx, err := c.RollupAddToken(token1Addr, clientSetup.RollupVariables.FeeAddToken)
|
||||||
require.Nil(t, err)
|
require.Nil(t, err)
|
||||||
assert.NotNil(t, tx)
|
assert.NotNil(t, tx)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user