Merge pull request #223 from hermeznetwork/feature/eth-remove-ERC777

Feature/eth remove erc777
This commit is contained in:
Eduard S
2020-10-26 16:20:41 +01:00
committed by GitHub
29 changed files with 1744 additions and 2425 deletions

View File

@@ -23,6 +23,7 @@ SyncLoopInterval = "1s"
Rollup = "0xEcc0a6dbC0bb4D51E4F84A315a9e5B0438cAD4f0"
Auction = "0x500D1d6A4c7D8Ae28240b47c8FCde034D827fD5e"
TokenHEZ = "0xf784709d2317D872237C4bC22f867d1BAe2913AB"
TokenHEZName = "Hermez Network Token"
[EthClient]
CallGasLimit = 300000

View File

@@ -68,9 +68,10 @@ type Node struct {
SyncLoopInterval Duration `validate:"required"`
} `validate:"required"`
SmartContracts struct {
Rollup ethCommon.Address `validate:"required"`
Auction ethCommon.Address `validate:"required"`
TokenHEZ ethCommon.Address `validate:"required"`
Rollup ethCommon.Address `validate:"required"`
Auction ethCommon.Address `validate:"required"`
TokenHEZ ethCommon.Address `validate:"required"`
TokenHEZName string `validate:"required"`
} `validate:"required"`
EthClient struct {
CallGasLimit uint64 `validate:"required"`

View File

@@ -178,9 +178,9 @@ func TestCoordinator(t *testing.T) {
// Bid for slot 2 and 4
_, err := ethClient.AuctionSetCoordinator(forger, "https://foo.bar")
require.Nil(t, err)
_, err = ethClient.AuctionBid(2, big.NewInt(9999))
_, err = ethClient.AuctionBidSimple(2, big.NewInt(9999))
require.Nil(t, err)
_, err = ethClient.AuctionBid(4, big.NewInt(9999))
_, err = ethClient.AuctionBidSimple(4, big.NewInt(9999))
require.Nil(t, err)
c := NewCoordinator(conf, hdb, txsel, bb, serverProofs, ethClient)

7
eth/.env.example Normal file
View File

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

62
eth/README.md Normal file
View File

@@ -0,0 +1,62 @@
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:
```
cd contracts/
yarn install
```
Go to where the deployment scripts for the test are found:
`cd scripts/ethclient-deployment/`
Now, a bash script (which uses gnome-terminal) has to be run to do the deployment:
`./test-deploy.sh`
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
Alternatively you can run the two previous commands manually in different terminals.
An output file necessary for the next step is obtained: `deploy-output`.
> The files that appear in `hermez-node/eth/contracts` must be generated 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 `hermez-node/eth/.env.example`
And then run test from `hermez-node/eth/`:
`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`

View File

@@ -2,7 +2,6 @@ package eth
import (
"context"
"encoding/binary"
"fmt"
"math/big"
"strings"
@@ -15,8 +14,7 @@ import (
"github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/ethclient"
HermezAuctionProtocol "github.com/hermeznetwork/hermez-node/eth/contracts/auction"
ERC777 "github.com/hermeznetwork/hermez-node/eth/contracts/erc777"
"golang.org/x/crypto/sha3"
HEZ "github.com/hermeznetwork/hermez-node/eth/contracts/tokenHEZ"
)
// AuctionConstants are the constants of the Rollup Smart Contract
@@ -237,8 +235,9 @@ type AuctionInterface interface {
AuctionGetSlotSet(slot int64) (*big.Int, error)
// Bidding
AuctionBid(slot int64, bidAmount *big.Int) (*types.Transaction, error)
AuctionMultiBid(startingSlot int64, endingSlot int64, slotSet [6]bool, maxBid, closedMinBid, budget *big.Int) (*types.Transaction, error)
AuctionBid(amount *big.Int, slot int64, bidAmount *big.Int, deadline *big.Int) (tx *types.Transaction, err error)
AuctionMultiBid(amount *big.Int, startingSlot, endingSlot int64, slotSets [6]bool,
maxBid, minBid, deadline *big.Int) (tx *types.Transaction, err error)
// Forge
AuctionCanForge(forger ethCommon.Address, blockNum int64) (bool, error)
@@ -262,15 +261,16 @@ type AuctionInterface interface {
// AuctionClient is the implementation of the interface to the Auction Smart Contract in ethereum.
type AuctionClient struct {
client *EthereumClient
address ethCommon.Address
tokenAddress ethCommon.Address
auction *HermezAuctionProtocol.HermezAuctionProtocol
contractAbi abi.ABI
client *EthereumClient
address ethCommon.Address
tokenHEZCfg TokenConfig
auction *HermezAuctionProtocol.HermezAuctionProtocol
tokenHEZ *HEZ.HEZ
contractAbi abi.ABI
}
// NewAuctionClient creates a new AuctionClient. `tokenAddress` is the address of the HEZ tokens.
func NewAuctionClient(client *EthereumClient, address, tokenAddress ethCommon.Address) (*AuctionClient, error) {
func NewAuctionClient(client *EthereumClient, address ethCommon.Address, tokenHEZCfg TokenConfig) (*AuctionClient, error) {
contractAbi, err := abi.JSON(strings.NewReader(string(HermezAuctionProtocol.HermezAuctionProtocolABI)))
if err != nil {
return nil, err
@@ -279,12 +279,17 @@ func NewAuctionClient(client *EthereumClient, address, tokenAddress ethCommon.Ad
if err != nil {
return nil, err
}
tokenHEZ, err := HEZ.NewHEZ(tokenHEZCfg.Address, client.Client())
if err != nil {
return nil, err
}
return &AuctionClient{
client: client,
address: address,
tokenAddress: tokenAddress,
auction: auction,
contractAbi: contractAbi,
client: client,
address: address,
tokenHEZCfg: tokenHEZCfg,
auction: auction,
tokenHEZ: tokenHEZ,
contractAbi: contractAbi,
}, nil
}
@@ -558,30 +563,24 @@ func (c *AuctionClient) AuctionGetSlotNumber(blockNum int64) (slot int64, err er
}
// AuctionBid is the interface to call the smart contract function
func (c *AuctionClient) AuctionBid(slot int64, bidAmount *big.Int) (tx *types.Transaction, err error) {
func (c *AuctionClient) AuctionBid(amount *big.Int, slot int64, bidAmount *big.Int, deadline *big.Int) (tx *types.Transaction, err error) {
if tx, err = c.client.CallAuth(
0,
func(ec *ethclient.Client, auth *bind.TransactOpts) (*types.Transaction, error) {
tokens, err := ERC777.NewERC777(c.tokenAddress, ec)
owner := c.client.account.Address
spender := c.address
nonce, err := c.tokenHEZ.Nonces(nil, owner)
if err != nil {
return nil, err
}
bidFnSignature := []byte("bid(uint128,uint128)")
hash := sha3.NewLegacyKeccak256()
_, err = hash.Write(bidFnSignature)
if err != nil {
return nil, err
}
methodID := hash.Sum(nil)[:4]
slotBytes := make([]byte, 8)
binary.BigEndian.PutUint64(slotBytes, uint64(slot))
paddedSlot := ethCommon.LeftPadBytes(slotBytes, 32)
paddedAmount := ethCommon.LeftPadBytes(bidAmount.Bytes(), 32)
var userData []byte
userData = append(userData, methodID...)
userData = append(userData, paddedSlot...)
userData = append(userData, paddedAmount...)
return tokens.Send(auth, c.address, bidAmount, userData)
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)
signature, _ := c.client.ks.SignHash(*c.client.account, digest)
permit := createPermit(owner, spender, amount, deadline, digest, signature)
_slot := big.NewInt(slot)
return c.auction.ProcessBid(auth, amount, _slot, bidAmount, permit)
},
); err != nil {
return nil, fmt.Errorf("Failed bid: %w", err)
@@ -590,46 +589,27 @@ func (c *AuctionClient) AuctionBid(slot int64, bidAmount *big.Int) (tx *types.Tr
}
// AuctionMultiBid is the interface to call the smart contract function
func (c *AuctionClient) AuctionMultiBid(startingSlot int64, endingSlot int64, slotSet [6]bool,
maxBid, closedMinBid, budget *big.Int) (tx *types.Transaction, err error) {
func (c *AuctionClient) AuctionMultiBid(amount *big.Int, startingSlot, endingSlot int64, slotSets [6]bool,
maxBid, minBid, deadline *big.Int) (tx *types.Transaction, err error) {
if tx, err = c.client.CallAuth(
1000000, //nolint:gomnd
func(ec *ethclient.Client, auth *bind.TransactOpts) (*types.Transaction, error) {
tokens, err := ERC777.NewERC777(c.tokenAddress, ec)
owner := c.client.account.Address
spender := c.address
nonce, err := c.tokenHEZ.Nonces(nil, owner)
if err != nil {
return nil, err
}
multiBidFnSignature := []byte("multiBid(uint128,uint128,bool[6],uint128,uint128)")
hash := sha3.NewLegacyKeccak256()
_, err = hash.Write(multiBidFnSignature)
if err != nil {
return nil, err
}
methodID := hash.Sum(nil)[:4]
startingSlotBytes := make([]byte, 8)
binary.BigEndian.PutUint64(startingSlotBytes, uint64(startingSlot))
paddedStartingSlot := ethCommon.LeftPadBytes(startingSlotBytes, 32)
endingSlotBytes := make([]byte, 8)
binary.BigEndian.PutUint64(endingSlotBytes, uint64(endingSlot))
paddedEndingSlot := ethCommon.LeftPadBytes(endingSlotBytes, 32)
paddedMinBid := ethCommon.LeftPadBytes(closedMinBid.Bytes(), 32)
paddedMaxBid := ethCommon.LeftPadBytes(maxBid.Bytes(), 32)
var userData []byte
userData = append(userData, methodID...)
userData = append(userData, paddedStartingSlot...)
userData = append(userData, paddedEndingSlot...)
for i := 0; i < len(slotSet); i++ {
if slotSet[i] {
paddedSlotSet := ethCommon.LeftPadBytes([]byte{1}, 32)
userData = append(userData, paddedSlotSet...)
} else {
paddedSlotSet := ethCommon.LeftPadBytes([]byte{0}, 32)
userData = append(userData, paddedSlotSet...)
}
}
userData = append(userData, paddedMaxBid...)
userData = append(userData, paddedMinBid...)
return tokens.Send(auth, c.address, budget, userData)
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)
signature, _ := c.client.ks.SignHash(*c.client.account, digest)
permit := createPermit(owner, spender, amount, deadline, digest, signature)
_startingSlot := big.NewInt(startingSlot)
_endingSlot := big.NewInt(endingSlot)
return c.auction.ProcessMultiBid(auth, amount, _startingSlot, _endingSlot, slotSets, maxBid, minBid, permit)
},
); err != nil {
return nil, fmt.Errorf("Failed multibid: %w", err)

View File

@@ -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 = 100
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)
@@ -40,8 +33,8 @@ 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.BlocksPerSlot, blocksPerSlot)
assert.Equal(t, auctionConstants.GenesisBlockNum, genesisBlock)
assert.Equal(t, auctionConstants.HermezRollup, hermezRollupAddressTestConst)
assert.Equal(t, auctionConstants.InitialMinimalBidding, INITMINBID)
assert.Equal(t, auctionConstants.TokenHEZ, tokenHEZAddressConst)
@@ -270,8 +263,10 @@ func TestAuctionBid(t *testing.T) {
require.Nil(t, err)
bidAmount := new(big.Int)
bidAmount.SetString("12000000000000000000", 10)
amount := new(big.Int)
amount.SetString("12000000000000000000", 10)
bidderAddress := governanceAddressConst
_, err = auctionClientTest.AuctionBid(currentSlot+4, bidAmount)
_, err = auctionClientTest.AuctionBid(amount, currentSlot+4, bidAmount, deadline)
require.Nil(t, err)
currentBlockNum, _ := auctionClientTest.client.EthCurrentBlock()
auctionEvents, _, _ := auctionClientTest.AuctionEventsByBlock(currentBlockNum)
@@ -282,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)
@@ -291,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)
@@ -309,7 +304,7 @@ func TestAuctionMultiBid(t *testing.T) {
budget := new(big.Int)
budget.SetString("45200000000000000000", 10)
bidderAddress := governanceAddressConst
_, err = auctionClientTest.AuctionMultiBid(currentSlot+4, currentSlot+10, slotSet, maxBid, minBid, budget)
_, err = auctionClientTest.AuctionMultiBid(budget, currentSlot+4, currentSlot+10, slotSet, maxBid, minBid, deadline)
require.Nil(t, err)
currentBlockNum, _ := auctionClientTest.client.EthCurrentBlock()
auctionEvents, _, _ := auctionClientTest.AuctionEventsByBlock(currentBlockNum)
@@ -346,17 +341,15 @@ func TestAuctionClaimHEZ(t *testing.T) {
}
func TestAuctionForge(t *testing.T) {
auctionClientTestHermez, err := NewAuctionClient(ethereumClientHermez, auctionTestAddressConst, tokenHEZAddressConst)
auctionClientTestHermez, err := NewAuctionClient(ethereumClientHermez, auctionTestAddressConst, tokenHEZ)
require.Nil(t, err)
slotConst := 4
blockNum := int64(int(BLOCKSPERSLOT)*slotConst + genesisBlock)
currentBlockNum, _ := auctionClientTest.client.EthCurrentBlock()
blockNum := int64(int(blocksPerSlot)*slotConst + int(genesisBlock))
currentBlockNum, _ := auctionClientTestHermez.client.EthCurrentBlock()
blocksToAdd := blockNum - currentBlockNum
addBlocks(blocksToAdd, ethClientDialURL)
currentBlockNum, _ = auctionClientTest.client.EthCurrentBlock()
currentBlockNum, _ = auctionClientTestHermez.client.EthCurrentBlock()
assert.Equal(t, currentBlockNum, blockNum)
_, err = auctionClientTestHermez.AuctionForge(bootCoordinatorAddressConst)
require.Contains(t, err.Error(), "Can't forge")
_, err = auctionClientTestHermez.AuctionForge(governanceAddressConst)
require.Nil(t, err)
}

View File

@@ -30,6 +30,12 @@ type Client struct {
RollupClient
}
// TokenConfig is used to define the information about token
type TokenConfig struct {
Address ethCommon.Address
Name string
}
// RollupConfig is the configuration for the Rollup smart contract interface
type RollupConfig struct {
Address ethCommon.Address
@@ -37,8 +43,8 @@ type RollupConfig struct {
// AuctionConfig is the configuration for the Auction smart contract interface
type AuctionConfig struct {
Address ethCommon.Address
TokenHEZAddress ethCommon.Address
Address ethCommon.Address
TokenHEZ TokenConfig
}
// ClientConfig is the configuration of the Client
@@ -51,11 +57,11 @@ type ClientConfig struct {
// NewClient creates a new Client to interact with Ethereum and the Hermez smart contracts.
func NewClient(client *ethclient.Client, account *accounts.Account, ks *ethKeystore.KeyStore, cfg *ClientConfig) (*Client, error) {
ethereumClient := NewEthereumClient(client, account, ks, &cfg.Ethereum)
auctionClient, err := NewAuctionClient(ethereumClient, cfg.Auction.Address, cfg.Auction.TokenHEZAddress)
auctionClient, err := NewAuctionClient(ethereumClient, cfg.Auction.Address, cfg.Auction.TokenHEZ)
if err != nil {
return nil, err
}
rollupCient, err := NewRollupClient(ethereumClient, cfg.Rollup.Address, cfg.Auction.TokenHEZAddress)
rollupCient, err := NewRollupClient(ethereumClient, cfg.Rollup.Address, cfg.Auction.TokenHEZ)
if err != nil {
return nil, err
}

View File

@@ -6,20 +6,12 @@ The go code of the contracts has been generated with the following command:
abigen --abi=WithdrawalDelayer.abi --bin=WithdrawalDelayer.bin --pkg=WithdrawalDelayer --out=WithdrawalDelayer.go
abigen --abi=Hermez.abi --bin=Hermez.bin --pkg=Hermez --out=Hermez.go
abigen --abi=HermezAuctionProtocol.abi --bin=HermezAuctionProtocol.bin --pkg=HermezAuctionProtocol --out=HermezAuctionProtocol.go
abigen --abi=ERC777.abi --bin=ERC777.bin --pkg=ERC777 --out=ERC777.go
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
Specifically they have been processed in the commit with hash: `60e03e981f1ce607c27d405952bfc98de376f0c5`
> abigen version 1.9.21
---
ERC20 go code was generated with the following command:
```
abigen --sol erc20.sol --pkg erc20 --out erc20/erc20.go
```
Branch: `RemoveERC777`
Specifically they have been processed in the commit with hash: `2a1cfccfba6770c1077ecea983d2c743dc4a1e93`
Versions:
```

File diff suppressed because one or more lines are too long

View File

@@ -1,19 +0,0 @@
pragma solidity ^0.7.0;
contract ERC20 {
string public constant name = "";
string public constant symbol = "";
uint8 public constant decimals = 0;
/*
function totalSupply() public constant returns (uint);
function balanceOf(address tokenOwner) public constant returns (uint balance);
function allowance(address tokenOwner, address spender) public constant returns (uint remaining);
function transfer(address to, uint tokens) public returns (bool success);
function approve(address spender, uint tokens) public returns (bool success);
function transferFrom(address from, address to, uint tokens) public returns (bool success);
event Transfer(address indexed from, address indexed to, uint tokens);
event Approval(address indexed tokenOwner, address indexed spender, uint tokens);
*/
}

View File

@@ -1,274 +0,0 @@
// Code generated - DO NOT EDIT.
// This file is a generated binding and any manual changes will be lost.
package erc20
import (
"math/big"
"strings"
ethereum "github.com/ethereum/go-ethereum"
"github.com/ethereum/go-ethereum/accounts/abi"
"github.com/ethereum/go-ethereum/accounts/abi/bind"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/event"
)
// Reference imports to suppress errors if they are not otherwise used.
var (
_ = big.NewInt
_ = strings.NewReader
_ = ethereum.NotFound
_ = bind.Bind
_ = common.Big1
_ = types.BloomLookup
_ = event.NewSubscription
)
// ERC20ABI is the input ABI used to generate the binding from.
const ERC20ABI = "[{\"inputs\":[],\"name\":\"decimals\",\"outputs\":[{\"internalType\":\"uint8\",\"name\":\"\",\"type\":\"uint8\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"name\",\"outputs\":[{\"internalType\":\"string\",\"name\":\"\",\"type\":\"string\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"symbol\",\"outputs\":[{\"internalType\":\"string\",\"name\":\"\",\"type\":\"string\"}],\"stateMutability\":\"view\",\"type\":\"function\"}]"
// ERC20FuncSigs maps the 4-byte function signature to its string representation.
var ERC20FuncSigs = map[string]string{
"313ce567": "decimals()",
"06fdde03": "name()",
"95d89b41": "symbol()",
}
// ERC20Bin is the compiled bytecode used for deploying new contracts.
var ERC20Bin = "0x608060405234801561001057600080fd5b50610123806100206000396000f3fe6080604052348015600f57600080fd5b5060043610603c5760003560e01c806306fdde03146041578063313ce5671460b957806395d89b41146041575b600080fd5b604760d5565b6040805160208082528351818301528351919283929083019185019080838360005b83811015607f5781810151838201526020016069565b50505050905090810190601f16801560ab5780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b60bf60e8565b6040805160ff9092168252519081900360200190f35b6040518060200160405280600081525081565b60008156fea26469706673582212209717f9f3c7b4f090e7741b44c5cb9425a26b593410462c0f4c2c0c0879db648d64736f6c63430007010033"
// DeployERC20 deploys a new Ethereum contract, binding an instance of ERC20 to it.
func DeployERC20(auth *bind.TransactOpts, backend bind.ContractBackend) (common.Address, *types.Transaction, *ERC20, error) {
parsed, err := abi.JSON(strings.NewReader(ERC20ABI))
if err != nil {
return common.Address{}, nil, nil, err
}
address, tx, contract, err := bind.DeployContract(auth, parsed, common.FromHex(ERC20Bin), backend)
if err != nil {
return common.Address{}, nil, nil, err
}
return address, tx, &ERC20{ERC20Caller: ERC20Caller{contract: contract}, ERC20Transactor: ERC20Transactor{contract: contract}, ERC20Filterer: ERC20Filterer{contract: contract}}, nil
}
// ERC20 is an auto generated Go binding around an Ethereum contract.
type ERC20 struct {
ERC20Caller // Read-only binding to the contract
ERC20Transactor // Write-only binding to the contract
ERC20Filterer // Log filterer for contract events
}
// ERC20Caller is an auto generated read-only Go binding around an Ethereum contract.
type ERC20Caller struct {
contract *bind.BoundContract // Generic contract wrapper for the low level calls
}
// ERC20Transactor is an auto generated write-only Go binding around an Ethereum contract.
type ERC20Transactor struct {
contract *bind.BoundContract // Generic contract wrapper for the low level calls
}
// ERC20Filterer is an auto generated log filtering Go binding around an Ethereum contract events.
type ERC20Filterer struct {
contract *bind.BoundContract // Generic contract wrapper for the low level calls
}
// ERC20Session is an auto generated Go binding around an Ethereum contract,
// with pre-set call and transact options.
type ERC20Session struct {
Contract *ERC20 // Generic contract binding to set the session for
CallOpts bind.CallOpts // Call options to use throughout this session
TransactOpts bind.TransactOpts // Transaction auth options to use throughout this session
}
// ERC20CallerSession is an auto generated read-only Go binding around an Ethereum contract,
// with pre-set call options.
type ERC20CallerSession struct {
Contract *ERC20Caller // Generic contract caller binding to set the session for
CallOpts bind.CallOpts // Call options to use throughout this session
}
// ERC20TransactorSession is an auto generated write-only Go binding around an Ethereum contract,
// with pre-set transact options.
type ERC20TransactorSession struct {
Contract *ERC20Transactor // Generic contract transactor binding to set the session for
TransactOpts bind.TransactOpts // Transaction auth options to use throughout this session
}
// ERC20Raw is an auto generated low-level Go binding around an Ethereum contract.
type ERC20Raw struct {
Contract *ERC20 // Generic contract binding to access the raw methods on
}
// ERC20CallerRaw is an auto generated low-level read-only Go binding around an Ethereum contract.
type ERC20CallerRaw struct {
Contract *ERC20Caller // Generic read-only contract binding to access the raw methods on
}
// ERC20TransactorRaw is an auto generated low-level write-only Go binding around an Ethereum contract.
type ERC20TransactorRaw struct {
Contract *ERC20Transactor // Generic write-only contract binding to access the raw methods on
}
// NewERC20 creates a new instance of ERC20, bound to a specific deployed contract.
func NewERC20(address common.Address, backend bind.ContractBackend) (*ERC20, error) {
contract, err := bindERC20(address, backend, backend, backend)
if err != nil {
return nil, err
}
return &ERC20{ERC20Caller: ERC20Caller{contract: contract}, ERC20Transactor: ERC20Transactor{contract: contract}, ERC20Filterer: ERC20Filterer{contract: contract}}, nil
}
// NewERC20Caller creates a new read-only instance of ERC20, bound to a specific deployed contract.
func NewERC20Caller(address common.Address, caller bind.ContractCaller) (*ERC20Caller, error) {
contract, err := bindERC20(address, caller, nil, nil)
if err != nil {
return nil, err
}
return &ERC20Caller{contract: contract}, nil
}
// NewERC20Transactor creates a new write-only instance of ERC20, bound to a specific deployed contract.
func NewERC20Transactor(address common.Address, transactor bind.ContractTransactor) (*ERC20Transactor, error) {
contract, err := bindERC20(address, nil, transactor, nil)
if err != nil {
return nil, err
}
return &ERC20Transactor{contract: contract}, nil
}
// NewERC20Filterer creates a new log filterer instance of ERC20, bound to a specific deployed contract.
func NewERC20Filterer(address common.Address, filterer bind.ContractFilterer) (*ERC20Filterer, error) {
contract, err := bindERC20(address, nil, nil, filterer)
if err != nil {
return nil, err
}
return &ERC20Filterer{contract: contract}, nil
}
// bindERC20 binds a generic wrapper to an already deployed contract.
func bindERC20(address common.Address, caller bind.ContractCaller, transactor bind.ContractTransactor, filterer bind.ContractFilterer) (*bind.BoundContract, error) {
parsed, err := abi.JSON(strings.NewReader(ERC20ABI))
if err != nil {
return nil, err
}
return bind.NewBoundContract(address, parsed, caller, transactor, filterer), nil
}
// Call invokes the (constant) contract method with params as input values and
// sets the output to result. The result type might be a single field for simple
// returns, a slice of interfaces for anonymous returns and a struct for named
// returns.
func (_ERC20 *ERC20Raw) Call(opts *bind.CallOpts, result interface{}, method string, params ...interface{}) error {
return _ERC20.Contract.ERC20Caller.contract.Call(opts, result, method, params...)
}
// Transfer initiates a plain transaction to move funds to the contract, calling
// its default method if one is available.
func (_ERC20 *ERC20Raw) Transfer(opts *bind.TransactOpts) (*types.Transaction, error) {
return _ERC20.Contract.ERC20Transactor.contract.Transfer(opts)
}
// Transact invokes the (paid) contract method with params as input values.
func (_ERC20 *ERC20Raw) Transact(opts *bind.TransactOpts, method string, params ...interface{}) (*types.Transaction, error) {
return _ERC20.Contract.ERC20Transactor.contract.Transact(opts, method, params...)
}
// Call invokes the (constant) contract method with params as input values and
// sets the output to result. The result type might be a single field for simple
// returns, a slice of interfaces for anonymous returns and a struct for named
// returns.
func (_ERC20 *ERC20CallerRaw) Call(opts *bind.CallOpts, result interface{}, method string, params ...interface{}) error {
return _ERC20.Contract.contract.Call(opts, result, method, params...)
}
// Transfer initiates a plain transaction to move funds to the contract, calling
// its default method if one is available.
func (_ERC20 *ERC20TransactorRaw) Transfer(opts *bind.TransactOpts) (*types.Transaction, error) {
return _ERC20.Contract.contract.Transfer(opts)
}
// Transact invokes the (paid) contract method with params as input values.
func (_ERC20 *ERC20TransactorRaw) Transact(opts *bind.TransactOpts, method string, params ...interface{}) (*types.Transaction, error) {
return _ERC20.Contract.contract.Transact(opts, method, params...)
}
// Decimals is a free data retrieval call binding the contract method 0x313ce567.
//
// Solidity: function decimals() view returns(uint8)
func (_ERC20 *ERC20Caller) Decimals(opts *bind.CallOpts) (uint8, error) {
var (
ret0 = new(uint8)
)
out := ret0
err := _ERC20.contract.Call(opts, out, "decimals")
return *ret0, err
}
// Decimals is a free data retrieval call binding the contract method 0x313ce567.
//
// Solidity: function decimals() view returns(uint8)
func (_ERC20 *ERC20Session) Decimals() (uint8, error) {
return _ERC20.Contract.Decimals(&_ERC20.CallOpts)
}
// Decimals is a free data retrieval call binding the contract method 0x313ce567.
//
// Solidity: function decimals() view returns(uint8)
func (_ERC20 *ERC20CallerSession) Decimals() (uint8, error) {
return _ERC20.Contract.Decimals(&_ERC20.CallOpts)
}
// Name is a free data retrieval call binding the contract method 0x06fdde03.
//
// Solidity: function name() view returns(string)
func (_ERC20 *ERC20Caller) Name(opts *bind.CallOpts) (string, error) {
var (
ret0 = new(string)
)
out := ret0
err := _ERC20.contract.Call(opts, out, "name")
return *ret0, err
}
// Name is a free data retrieval call binding the contract method 0x06fdde03.
//
// Solidity: function name() view returns(string)
func (_ERC20 *ERC20Session) Name() (string, error) {
return _ERC20.Contract.Name(&_ERC20.CallOpts)
}
// Name is a free data retrieval call binding the contract method 0x06fdde03.
//
// Solidity: function name() view returns(string)
func (_ERC20 *ERC20CallerSession) Name() (string, error) {
return _ERC20.Contract.Name(&_ERC20.CallOpts)
}
// Symbol is a free data retrieval call binding the contract method 0x95d89b41.
//
// Solidity: function symbol() view returns(string)
func (_ERC20 *ERC20Caller) Symbol(opts *bind.CallOpts) (string, error) {
var (
ret0 = new(string)
)
out := ret0
err := _ERC20.contract.Call(opts, out, "symbol")
return *ret0, err
}
// Symbol is a free data retrieval call binding the contract method 0x95d89b41.
//
// Solidity: function symbol() view returns(string)
func (_ERC20 *ERC20Session) Symbol() (string, error) {
return _ERC20.Contract.Symbol(&_ERC20.CallOpts)
}
// Symbol is a free data retrieval call binding the contract method 0x95d89b41.
//
// Solidity: function symbol() view returns(string)
func (_ERC20 *ERC20CallerSession) Symbol() (string, error) {
return _ERC20.Contract.Symbol(&_ERC20.CallOpts)
}

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

File diff suppressed because one or more lines are too long

View File

@@ -13,7 +13,7 @@ import (
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/ethclient"
"github.com/hermeznetwork/hermez-node/common"
"github.com/hermeznetwork/hermez-node/eth/contracts/erc20"
HEZ "github.com/hermeznetwork/hermez-node/eth/contracts/tokenHEZ"
"github.com/hermeznetwork/hermez-node/log"
)
@@ -277,7 +277,9 @@ func (c *EthereumClient) EthBlockByNumber(ctx context.Context, number int64) (*c
// EthERC20Consts returns the constants defined for a particular ERC20 Token instance.
func (c *EthereumClient) EthERC20Consts(tokenAddress ethCommon.Address) (*ERC20Consts, error) {
instance, err := erc20.NewERC20(tokenAddress, c.client)
// We use the HEZ token smart contract interfacehere because it's an
// ERC20, which allows us to access the standard ERC20 constants.
instance, err := HEZ.NewHEZ(tokenAddress, c.client)
if err != nil {
return nil, err
}

View File

@@ -13,9 +13,9 @@ func TestEthERC20(t *testing.T) {
require.Nil(t, err)
client := NewEthereumClient(ethClient, accountAux, ks, nil)
consts, err := client.EthERC20Consts(tokenERC20AddressConst)
consts, err := client.EthERC20Consts(tokenHEZAddressConst)
require.Nil(t, err)
assert.Equal(t, "ERC20_0", consts.Name)
assert.Equal(t, "20_0", consts.Symbol)
assert.Equal(t, "Hermez Network Token", consts.Name)
assert.Equal(t, "HEZ", consts.Symbol)
assert.Equal(t, uint64(18), consts.Decimals)
}

View File

@@ -2,9 +2,13 @@ package eth
import (
"fmt"
"math/big"
"net/http"
"strconv"
"strings"
ethCommon "github.com/ethereum/go-ethereum/common"
"golang.org/x/crypto/sha3"
)
func addBlock(url string) {
@@ -61,3 +65,90 @@ func addTime(seconds float64, url string) {
}
}()
}
func createPermitDigest(tokenAddr, owner, spender ethCommon.Address, chainID, value, nonce, deadline *big.Int, tokenName string) ([]byte, error) {
// NOTE: We ignore hash.Write errors because we are writing to a memory
// buffer and don't expect any errors to occur.
abiPermit := []byte("Permit(address owner,address spender,uint256 value,uint256 nonce,uint256 deadline)")
hashPermit := sha3.NewLegacyKeccak256()
hashPermit.Write(abiPermit) //nolint:errcheck,gosec
abiEIP712Domain := []byte("EIP712Domain(string name,string version,uint256 chainId,address verifyingContract)")
hashEIP712Domain := sha3.NewLegacyKeccak256()
hashEIP712Domain.Write(abiEIP712Domain) //nolint:errcheck,gosec
var encodeBytes []byte
paddedHash := ethCommon.LeftPadBytes(hashEIP712Domain.Sum(nil), 32)
hashName := sha3.NewLegacyKeccak256()
hashName.Write([]byte(tokenName)) //nolint:errcheck,gosec
paddedName := ethCommon.LeftPadBytes(hashName.Sum(nil), 32)
hashVersion := sha3.NewLegacyKeccak256()
hashVersion.Write([]byte("1")) //nolint:errcheck,gosec
paddedX := ethCommon.LeftPadBytes(hashVersion.Sum(nil), 32)
paddedChainID := ethCommon.LeftPadBytes(chainID.Bytes(), 32)
paddedAddr := ethCommon.LeftPadBytes(tokenAddr.Bytes(), 32)
encodeBytes = append(encodeBytes, paddedHash...)
encodeBytes = append(encodeBytes, paddedName...)
encodeBytes = append(encodeBytes, paddedX...)
encodeBytes = append(encodeBytes, paddedChainID...)
encodeBytes = append(encodeBytes, paddedAddr...)
_domainSeparator := sha3.NewLegacyKeccak256()
_domainSeparator.Write(encodeBytes) //nolint:errcheck,gosec
var bytes1 []byte
paddedHashPermit := ethCommon.LeftPadBytes(hashPermit.Sum(nil), 32)
paddedOwner := ethCommon.LeftPadBytes(owner.Bytes(), 32)
paddedSpender := ethCommon.LeftPadBytes(spender.Bytes(), 32)
paddedValue := ethCommon.LeftPadBytes(value.Bytes(), 32)
paddedNonce := ethCommon.LeftPadBytes(nonce.Bytes(), 32)
paddedDeadline := ethCommon.LeftPadBytes(deadline.Bytes(), 32)
bytes1 = append(bytes1, paddedHashPermit...)
bytes1 = append(bytes1, paddedOwner...)
bytes1 = append(bytes1, paddedSpender...)
bytes1 = append(bytes1, paddedValue...)
bytes1 = append(bytes1, paddedNonce...)
bytes1 = append(bytes1, paddedDeadline...)
hashBytes1 := sha3.NewLegacyKeccak256()
hashBytes1.Write(bytes1) //nolint:errcheck,gosec
var bytes2 []byte
paddedY := ethCommon.LeftPadBytes([]byte{0x19}, 1)
paddedZ := ethCommon.LeftPadBytes([]byte{0x01}, 1)
paddedDomainSeparator := ethCommon.LeftPadBytes(_domainSeparator.Sum(nil), 32)
paddedHashBytes1 := ethCommon.LeftPadBytes(hashBytes1.Sum(nil), 32)
bytes2 = append(bytes2, paddedY...)
bytes2 = append(bytes2, paddedZ...)
bytes2 = append(bytes2, paddedDomainSeparator...)
bytes2 = append(bytes2, paddedHashBytes1...)
hashBytes2 := sha3.NewLegacyKeccak256()
hashBytes2.Write(bytes2) //nolint:errcheck,gosec
return hashBytes2.Sum(nil), nil
}
func createPermit(owner, spender ethCommon.Address, amount, deadline *big.Int, digest, signature []byte) []byte {
r := signature[0:32]
s := signature[32:64]
v := signature[64] + byte(27) //nolint:gomnd
ABIpermit := []byte("permit(address,address,uint256,uint256,uint8,bytes32,bytes32)")
hash := sha3.NewLegacyKeccak256()
hash.Write(ABIpermit) //nolint:errcheck,gosec
methodID := hash.Sum(nil)[:4]
var permit []byte
paddedOwner := ethCommon.LeftPadBytes(owner.Bytes(), 32)
paddedSpender := ethCommon.LeftPadBytes(spender.Bytes(), 32)
paddedAmount := ethCommon.LeftPadBytes(amount.Bytes(), 32)
paddedDeadline := ethCommon.LeftPadBytes(deadline.Bytes(), 32)
paddedV := ethCommon.LeftPadBytes([]byte{v}, 32)
permit = append(permit, methodID...)
permit = append(permit, paddedOwner...)
permit = append(permit, paddedSpender...)
permit = append(permit, paddedAmount...)
permit = append(permit, paddedDeadline...)
permit = append(permit, paddedV...)
permit = append(permit, r...)
permit = append(permit, s...)
return permit
}

View File

@@ -1,8 +1,11 @@
package eth
import (
"fmt"
"io/ioutil"
"math/big"
"os"
"strconv"
"testing"
"github.com/ethereum/go-ethereum/accounts"
@@ -10,40 +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 errEnvVar = fmt.Errorf("Some environment variable is missing")
var (
ethClientDialURL = "http://localhost:8545"
password = "pass"
deadline, _ = new(big.Int).SetString("ffffffffffffffffffffffffffffffff", 16)
)
// Smart Contract Addresses
var (
auctionAddressStr = "0x500D1d6A4c7D8Ae28240b47c8FCde034D827fD5e"
auctionAddressConst = ethCommon.HexToAddress(auctionAddressStr)
auctionTestAddressStr = "0x1d80315fac6aBd3EfeEbE97dEc44461ba7556160"
auctionTestAddressConst = ethCommon.HexToAddress(auctionTestAddressStr)
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)
tokenERC777AddressStr = "0xf784709d2317D872237C4bC22f867d1BAe2913AB" //nolint:gosec
tokenERC777AddressConst = ethCommon.HexToAddress(tokenERC777AddressStr)
tokenERC20AddressStr = "0x3619DbE27d7c1e7E91aA738697Ae7Bc5FC3eACA5" //nolint:gosec
tokenERC20AddressConst = ethCommon.HexToAddress(tokenERC20AddressStr)
tokenHEZAddressConst = tokenERC777AddressConst
hermezRollupAddressStr = "0xEcc0a6dbC0bb4D51E4F84A315a9e5B0438cAD4f0"
hermezRollupAddressConst = ethCommon.HexToAddress(hermezRollupAddressStr)
wdelayerAddressStr = "0xD6C850aeBFDC46D7F4c207e445cC0d6B0919BDBe"
wdelayerAddressConst = ethCommon.HexToAddress(wdelayerAddressStr)
wdelayerTestAddressStr = "0x52d3b94181f8654db2530b0fEe1B19173f519C52"
wdelayerTestAddressConst = ethCommon.HexToAddress(wdelayerTestAddressStr)
safetyAddressStr = "0xE5904695748fe4A84b40b3fc79De2277660BD1D3"
safetyAddressConst = ethCommon.HexToAddress(safetyAddressStr)
)
@@ -70,6 +65,10 @@ var (
auxAddressStr = "0x3d91185a02774C70287F6c74Dd26d13DFB58ff16"
auxAddressConst = ethCommon.HexToAddress(auxAddressStr)
aux2AddressSK = "28d1bfbbafe9d1d4f5a11c3c16ab6bf9084de48d99fbac4058bdfa3c80b29087"
// aux2AddressStr = "0x532792b73c0c6e7565912e7039c59986f7e1dd1f"
// aux2AddressConst = ethCommon.HexToAddress(aux2AddressStr)
hermezRollupTestSK = "28d1bfbbafe9d1d4f5a11c3c16ab6bf9084de48d99fbac4058bdfa3c80b29088"
hermezRollupTestAddressStr = "0xEa960515F8b4C237730F028cBAcF0a28E7F45dE0"
hermezRollupAddressTestConst = ethCommon.HexToAddress(hermezRollupTestAddressStr)
@@ -81,6 +80,7 @@ var (
accountWhite *accounts.Account
accountGovDAO *accounts.Account
accountAux *accounts.Account
accountAux2 *accounts.Account
accountHermez *accounts.Account
ks *keystore.KeyStore
ethClient *ethclient.Client
@@ -88,6 +88,7 @@ var (
ethereumClientKep *EthereumClient
ethereumClientGovDAO *EthereumClient
ethereumClientAux *EthereumClient
ethereumClientAux2 *EthereumClient
ethereumClientHermez *EthereumClient
)
@@ -107,10 +108,45 @@ func addKey(ks *keystore.KeyStore, skHex string) *accounts.Account {
return &account
}
func getEnvVariables() {
err := godotenv.Load()
if err != nil {
fmt.Println("Variables loaded from environment")
} 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)
}
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)
@@ -128,6 +164,7 @@ func TestMain(m *testing.M) {
accountWhite = addKey(ks, whiteHackGroupAddressSK)
accountGovDAO = addKey(ks, hermezGovernanceDAOAddressSK)
accountAux = addKey(ks, auxAddressSK)
accountAux2 = addKey(ks, aux2AddressSK)
accountHermez = addKey(ks, hermezRollupTestSK)
ethClient, err = ethclient.Dial(ethClientDialURL)
@@ -136,17 +173,16 @@ func TestMain(m *testing.M) {
}
// Controllable Governance Address
ethereumClientGov := NewEthereumClient(ethClient, accountGov, ks, nil)
auctionClient, err = NewAuctionClient(ethereumClientGov, auctionAddressConst, tokenHEZAddressConst)
auctionClient, err = NewAuctionClient(ethereumClientGov, auctionAddressConst, tokenHEZ)
if err != nil {
panic(err)
}
auctionClientTest, err = NewAuctionClient(ethereumClientGov, auctionTestAddressConst, tokenHEZAddressConst)
auctionClientTest, err = NewAuctionClient(ethereumClientGov, auctionTestAddressConst, tokenHEZ)
if err != nil {
panic(err)
}
rollupClient, err = NewRollupClient(ethereumClientGov, hermezRollupAddressConst, tokenHEZAddressConst)
rollupClient, err = NewRollupClient(ethereumClientGov, hermezRollupAddressConst, tokenHEZ)
if err != nil {
panic(err)
}
@@ -163,6 +199,7 @@ func TestMain(m *testing.M) {
ethereumClientWhite = NewEthereumClient(ethClient, accountWhite, ks, nil)
ethereumClientGovDAO = NewEthereumClient(ethClient, accountGovDAO, ks, nil)
ethereumClientAux = NewEthereumClient(ethClient, accountAux, ks, nil)
ethereumClientAux2 = NewEthereumClient(ethClient, accountAux2, ks, nil)
ethereumClientHermez = NewEthereumClient(ethClient, accountHermez, ks, nil)
exitVal = m.Run()

View File

@@ -14,11 +14,10 @@ import (
"github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/ethclient"
"github.com/hermeznetwork/hermez-node/common"
ERC777 "github.com/hermeznetwork/hermez-node/eth/contracts/erc777"
Hermez "github.com/hermeznetwork/hermez-node/eth/contracts/hermez"
HEZ "github.com/hermeznetwork/hermez-node/eth/contracts/tokenHEZ"
"github.com/hermeznetwork/hermez-node/log"
"github.com/iden3/go-iden3-crypto/babyjub"
"golang.org/x/crypto/sha3"
)
const (
@@ -259,13 +258,13 @@ type RollupInterface interface {
// Public Functions
RollupForgeBatch(*RollupForgeBatchArgs) (*types.Transaction, error)
RollupAddToken(tokenAddress ethCommon.Address, feeAddToken *big.Int) (*types.Transaction, error)
RollupAddToken(tokenAddress ethCommon.Address, feeAddToken, deadline *big.Int) (*types.Transaction, error)
RollupWithdrawMerkleProof(babyPubKey *babyjub.PublicKey, tokenID uint32, numExitRoot, idx int64, amount *big.Int, siblings []*big.Int, instantWithdraw bool) (*types.Transaction, error)
RollupWithdrawCircuit(proofA, proofC [2]*big.Int, proofB [2][2]*big.Int, tokenID uint32, numExitRoot, idx int64, amount *big.Int, instantWithdraw bool) (*types.Transaction, error)
RollupL1UserTxERC20ETH(fromBJJ *babyjub.PublicKey, fromIdx int64, loadAmount *big.Int, amount *big.Int, tokenID uint32, toIdx int64) (*types.Transaction, error)
RollupL1UserTxERC777(fromBJJ *babyjub.PublicKey, fromIdx int64, loadAmount *big.Int, amount *big.Int, tokenID uint32, toIdx int64) (*types.Transaction, error)
RollupL1UserTxERC20Permit(fromBJJ *babyjub.PublicKey, fromIdx int64, loadAmount *big.Int, amount *big.Int, tokenID uint32, toIdx int64, deadline *big.Int) (tx *types.Transaction, err error)
// Governance Public Functions
RollupUpdateForgeL1L2BatchTimeout(newForgeL1L2BatchTimeout int64) (*types.Transaction, error)
@@ -289,15 +288,16 @@ type RollupInterface interface {
// RollupClient is the implementation of the interface to the Rollup Smart Contract in ethereum.
type RollupClient struct {
client *EthereumClient
address ethCommon.Address
tokenHEZAddress ethCommon.Address
hermez *Hermez.Hermez
contractAbi abi.ABI
client *EthereumClient
address ethCommon.Address
tokenHEZCfg TokenConfig
hermez *Hermez.Hermez
tokenHEZ *HEZ.HEZ
contractAbi abi.ABI
}
// NewRollupClient creates a new RollupClient
func NewRollupClient(client *EthereumClient, address ethCommon.Address, tokenHEZAddress ethCommon.Address) (*RollupClient, error) {
func NewRollupClient(client *EthereumClient, address ethCommon.Address, tokenHEZCfg TokenConfig) (*RollupClient, error) {
contractAbi, err := abi.JSON(strings.NewReader(string(Hermez.HermezABI)))
if err != nil {
return nil, err
@@ -306,12 +306,17 @@ func NewRollupClient(client *EthereumClient, address ethCommon.Address, tokenHEZ
if err != nil {
return nil, err
}
tokenHEZ, err := HEZ.NewHEZ(tokenHEZCfg.Address, client.Client())
if err != nil {
return nil, err
}
return &RollupClient{
client: client,
address: address,
tokenHEZAddress: tokenHEZAddress,
hermez: hermez,
contractAbi: contractAbi,
client: client,
address: address,
tokenHEZCfg: tokenHEZCfg,
hermez: hermez,
tokenHEZ: tokenHEZ,
contractAbi: contractAbi,
}, nil
}
@@ -372,26 +377,24 @@ func (c *RollupClient) RollupForgeBatch(args *RollupForgeBatchArgs) (tx *types.T
// 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) (tx *types.Transaction, err error) {
func (c *RollupClient) RollupAddToken(tokenAddress ethCommon.Address, feeAddToken, deadline *big.Int) (tx *types.Transaction, err error) {
if tx, err = c.client.CallAuth(
0,
func(ec *ethclient.Client, auth *bind.TransactOpts) (*types.Transaction, error) {
tokens, err := ERC777.NewERC777(c.tokenHEZAddress, ec)
owner := c.client.account.Address
spender := c.address
nonce, err := c.tokenHEZ.Nonces(nil, owner)
if err != nil {
return nil, err
}
addTokenFnSignature := []byte("addToken(address)")
hash := sha3.NewLegacyKeccak256()
_, err = hash.Write(addTokenFnSignature)
if err != nil {
return nil, err
}
methodID := hash.Sum(nil)[:4]
var data []byte
data = append(data, methodID...)
paddedAddress := ethCommon.LeftPadBytes(tokenAddress.Bytes(), 32)
data = append(data, paddedAddress[:]...)
return tokens.Send(auth, c.address, feeAddToken, data)
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)
signature, _ := c.client.ks.SignHash(*c.client.account, digest)
permit := createPermit(owner, spender, feeAddToken, deadline, digest, signature)
return c.hermez.AddToken(auth, tokenAddress, permit)
},
); err != nil {
return nil, fmt.Errorf("Failed add Token %w", err)
@@ -404,16 +407,12 @@ func (c *RollupClient) RollupWithdrawMerkleProof(fromBJJ *babyjub.PublicKey, tok
if tx, err = c.client.CallAuth(
0,
func(ec *ethclient.Client, auth *bind.TransactOpts) (*types.Transaction, error) {
hermez, err := Hermez.NewHermez(c.address, ec)
if err != nil {
return nil, err
}
pkCompL := fromBJJ.Compress()
pkCompB := common.SwapEndianness(pkCompL[:])
babyPubKey := new(big.Int).SetBytes(pkCompB)
numExitRootB := big.NewInt(numExitRoot)
idxBig := big.NewInt(idx)
return hermez.WithdrawMerkleProof(auth, tokenID, amount, babyPubKey, numExitRootB, siblings, idxBig, instantWithdraw)
return c.hermez.WithdrawMerkleProof(auth, tokenID, amount, babyPubKey, numExitRootB, siblings, idxBig, instantWithdraw)
},
); err != nil {
return nil, fmt.Errorf("Failed update WithdrawMerkleProof: %w", err)
@@ -432,16 +431,11 @@ func (c *RollupClient) RollupL1UserTxERC20ETH(fromBJJ *babyjub.PublicKey, fromId
if tx, err = c.client.CallAuth(
0,
func(ec *ethclient.Client, auth *bind.TransactOpts) (*types.Transaction, error) {
hermez, err := Hermez.NewHermez(c.address, ec)
if err != nil {
return nil, err
}
pkCompL := fromBJJ.Compress()
pkCompB := common.SwapEndianness(pkCompL[:])
babyPubKey := new(big.Int).SetBytes(pkCompB)
fromIdxBig := big.NewInt(fromIdx)
toIdxBig := big.NewInt(toIdx)
tokenIDBig := uint32(tokenID)
loadAmountF, err := common.NewFloat16(loadAmount)
if err != nil {
return nil, err
@@ -453,7 +447,9 @@ func (c *RollupClient) RollupL1UserTxERC20ETH(fromBJJ *babyjub.PublicKey, fromId
if tokenID == 0 {
auth.Value = loadAmount
}
return hermez.AddL1Transaction(auth, babyPubKey, fromIdxBig, uint16(loadAmountF), uint16(amountF), tokenIDBig, toIdxBig)
var permit []byte
return c.hermez.AddL1Transaction(auth, babyPubKey, fromIdxBig, uint16(loadAmountF),
uint16(amountF), tokenID, toIdxBig, permit)
},
); err != nil {
return nil, fmt.Errorf("Failed add L1 Tx ERC20/ETH: %w", err)
@@ -461,59 +457,44 @@ func (c *RollupClient) RollupL1UserTxERC20ETH(fromBJJ *babyjub.PublicKey, fromId
return tx, nil
}
// RollupL1UserTxERC777 is the interface to call the smart contract function
func (c *RollupClient) RollupL1UserTxERC777(fromBJJ *babyjub.PublicKey, fromIdx int64, loadAmount *big.Int, amount *big.Int, tokenID uint32, toIdx int64) (tx *types.Transaction, err error) {
// RollupL1UserTxERC20Permit is the interface to call the smart contract function
func (c *RollupClient) RollupL1UserTxERC20Permit(fromBJJ *babyjub.PublicKey, fromIdx int64, loadAmount *big.Int, amount *big.Int, tokenID uint32, toIdx int64, deadline *big.Int) (tx *types.Transaction, err error) {
if tx, err = c.client.CallAuth(
0,
func(ec *ethclient.Client, auth *bind.TransactOpts) (*types.Transaction, error) {
tokens, err := ERC777.NewERC777(c.tokenHEZAddress, ec)
if err != nil {
return nil, err
}
addL1TxFnSignature := []byte("addL1Transaction(uint256,uint48,uint16,uint16,uint32,uint48)")
hash := sha3.NewLegacyKeccak256()
_, err = hash.Write(addL1TxFnSignature)
if err != nil {
return nil, err
}
methodID := hash.Sum(nil)[:4]
pkCompL := fromBJJ.Compress()
pkCompB := common.SwapEndianness(pkCompL[:])
paddedAddress := ethCommon.LeftPadBytes(pkCompB, 32)
fromIdxB, err := common.Idx(fromIdx).Bytes()
if err != nil {
return nil, err
}
paddedFromIdx := ethCommon.LeftPadBytes(fromIdxB[:], 32)
babyPubKey := new(big.Int).SetBytes(pkCompB)
fromIdxBig := big.NewInt(fromIdx)
toIdxBig := big.NewInt(toIdx)
loadAmountF, err := common.NewFloat16(loadAmount)
if err != nil {
return nil, err
}
paddedLoadAmount := ethCommon.LeftPadBytes(loadAmountF.Bytes(), 32)
amountF, err := common.NewFloat16(amount)
if err != nil {
return nil, err
}
paddedAmount := ethCommon.LeftPadBytes(amountF.Bytes(), 32)
tokenIDB := common.TokenID(tokenID).Bytes()
paddedTokenID := ethCommon.LeftPadBytes(tokenIDB, 32)
toIdxB, err := common.Idx(toIdx).Bytes()
if tokenID == 0 {
auth.Value = loadAmount
}
owner := c.client.account.Address
spender := c.address
nonce, err := c.tokenHEZ.Nonces(nil, owner)
if err != nil {
return nil, err
}
paddedToIdx := ethCommon.LeftPadBytes(toIdxB[:], 32)
var data []byte
data = append(data, methodID...)
data = append(data, paddedAddress[:]...)
data = append(data, paddedFromIdx[:]...)
data = append(data, paddedLoadAmount[:]...)
data = append(data, paddedAmount[:]...)
data = append(data, paddedTokenID[:]...)
data = append(data, paddedToIdx[:]...)
return tokens.Send(auth, c.address, loadAmount, data)
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)
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),
uint16(amountF), tokenID, toIdxBig, permit)
},
); err != nil {
return nil, fmt.Errorf("Failed add L1 Tx ERC777: %w", err)
return nil, fmt.Errorf("Failed add L1 Tx ERC20Permit: %w", err)
}
return tx, nil
}
@@ -539,11 +520,7 @@ func (c *RollupClient) RollupUpdateForgeL1L2BatchTimeout(newForgeL1L2BatchTimeou
if tx, err = c.client.CallAuth(
0,
func(ec *ethclient.Client, auth *bind.TransactOpts) (*types.Transaction, error) {
hermez, err := Hermez.NewHermez(c.address, ec)
if err != nil {
return nil, err
}
return hermez.UpdateForgeL1L2BatchTimeout(auth, uint8(newForgeL1L2BatchTimeout))
return c.hermez.UpdateForgeL1L2BatchTimeout(auth, uint8(newForgeL1L2BatchTimeout))
},
); err != nil {
return nil, fmt.Errorf("Failed update ForgeL1L2BatchTimeout: %w", err)
@@ -556,11 +533,7 @@ func (c *RollupClient) RollupUpdateFeeAddToken(newFeeAddToken *big.Int) (tx *typ
if tx, err = c.client.CallAuth(
0,
func(ec *ethclient.Client, auth *bind.TransactOpts) (*types.Transaction, error) {
hermez, err := Hermez.NewHermez(c.address, ec)
if err != nil {
return nil, err
}
return hermez.UpdateFeeAddToken(auth, newFeeAddToken)
return c.hermez.UpdateFeeAddToken(auth, newFeeAddToken)
},
); err != nil {
return nil, fmt.Errorf("Failed update FeeAddToken: %w", err)

View File

@@ -26,7 +26,7 @@ var maxTx = int64(512)
var nLevels = int64(32)
var tokenIDERC777 uint32
var tokenIDERC20 uint32
var tokenHEZID uint32
type keys struct {
BJJSecretKey *babyjub.PrivateKey
@@ -56,7 +56,7 @@ func TestRollupConstants(t *testing.T) {
require.Nil(t, err)
assert.Equal(t, absoluteMaxL1L2BatchTimeout, rollupConstants.AbsoluteMaxL1L2BatchTimeout)
assert.Equal(t, auctionAddressConst, rollupConstants.HermezAuctionContract)
assert.Equal(t, tokenERC777AddressConst, rollupConstants.TokenHEZ)
assert.Equal(t, tokenHEZAddressConst, rollupConstants.TokenHEZ)
assert.Equal(t, maxTx, rollupConstants.Verifiers[0].MaxTx)
assert.Equal(t, nLevels, rollupConstants.Verifiers[0].NLevels)
assert.Equal(t, governanceAddressConst, rollupConstants.HermezGovernanceDAOAddress)
@@ -72,29 +72,17 @@ func TestRollupRegisterTokensCount(t *testing.T) {
func TestAddToken(t *testing.T) {
feeAddToken := big.NewInt(10)
// Addtoken ERC20
// Addtoken ERC20Permit
registerTokensCount, err := rollupClient.RollupRegisterTokensCount()
require.Nil(t, err)
_, err = rollupClient.RollupAddToken(tokenERC20AddressConst, feeAddToken)
_, err = rollupClient.RollupAddToken(tokenHEZAddressConst, feeAddToken, deadline)
require.Nil(t, err)
currentBlockNum, _ := rollupClient.client.EthCurrentBlock()
rollupEvents, _, _ := rollupClient.RollupEventsByBlock(currentBlockNum)
assert.Equal(t, tokenERC20AddressConst, rollupEvents.AddToken[0].TokenAddress)
assert.Equal(t, tokenHEZAddressConst, rollupEvents.AddToken[0].TokenAddress)
assert.Equal(t, registerTokensCount, common.TokenID(rollupEvents.AddToken[0].TokenID).BigInt())
tokenIDERC20 = rollupEvents.AddToken[0].TokenID
// Addtoken ERC777
registerTokensCount, err = rollupClient.RollupRegisterTokensCount()
require.Nil(t, err)
_, err = rollupClient.RollupAddToken(tokenERC777AddressConst, feeAddToken)
require.Nil(t, err)
currentBlockNum, _ = rollupClient.client.EthCurrentBlock()
rollupEvents, _, _ = rollupClient.RollupEventsByBlock(currentBlockNum)
assert.Equal(t, tokenERC777AddressConst, rollupEvents.AddToken[0].TokenAddress)
assert.Equal(t, registerTokensCount, common.TokenID(rollupEvents.AddToken[0].TokenID).BigInt())
tokenIDERC777 = rollupEvents.AddToken[0].TokenID
tokenHEZID = rollupEvents.AddToken[0].TokenID
}
func TestRollupForgeBatch(t *testing.T) {
@@ -113,32 +101,17 @@ func TestRollupForgeBatch(t *testing.T) {
minBid.SetString("11000000000000000000", 10)
budget := new(big.Int)
budget.SetString("45200000000000000000", 10)
_, err = auctionClient.AuctionMultiBid(currentSlot+4, currentSlot+10, slotSet, maxBid, minBid, budget)
_, err = auctionClient.AuctionMultiBid(budget, currentSlot+4, currentSlot+10, slotSet, maxBid, minBid, deadline)
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)
// Forge
args := new(RollupForgeBatchArgs)
// feeIdxCoordinatorBytes, err := hex.DecodeString("00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000")
// require.Nil(t, err)
// lenFeeIdxCoordinatorBytes := int(4)
// numFeeIdxCoordinator := len(feeIdxCoordinatorBytes) / lenFeeIdxCoordinatorBytes
// for i := 0; i < numFeeIdxCoordinator; i++ {
// var paddedFeeIdx [6]byte
// if lenFeeIdxCoordinatorBytes < common.IdxBytesLen {
// copy(paddedFeeIdx[6-lenFeeIdxCoordinatorBytes:], feeIdxCoordinatorBytes[i*lenFeeIdxCoordinatorBytes:(i+1)*lenFeeIdxCoordinatorBytes])
// } else {
// copy(paddedFeeIdx[:], feeIdxCoordinatorBytes[i*lenFeeIdxCoordinatorBytes:(i+1)*lenFeeIdxCoordinatorBytes])
// }
// FeeIdxCoordinator, err := common.IdxFromBytes(paddedFeeIdx[:])
// require.Nil(t, err)
// args.FeeIdxCoordinator = append(args.FeeIdxCoordinator, FeeIdxCoordinator)
// }
args.FeeIdxCoordinator = []common.Idx{} // When encoded, 64 times the 0 idx means that no idx to collect fees is specified.
l1CoordinatorBytes, err := hex.DecodeString("1c660323607bb113e586183609964a333d07ebe4bef3be82ec13af453bae9590bd7711cdb6abf42f176eadfbe5506fbef5e092e5543733f91b0061d9a7747fa10694a915a6470fa230de387b51e6f4db0b09787867778687b55197ad6d6a86eac000000001")
require.Nil(t, err)
@@ -226,7 +199,7 @@ func TestRollupUpdateFeeAddToken(t *testing.T) {
}
func TestRollupL1UserTxETHCreateAccountDeposit(t *testing.T) {
rollupClientAux, err := NewRollupClient(ethereumClientAux, hermezRollupAddressConst, tokenHEZAddressConst)
rollupClientAux, err := NewRollupClient(ethereumClientAux, hermezRollupAddressConst, tokenHEZ)
require.Nil(t, err)
key := genKeysBjj(2)
fromIdxInt64 := int64(0)
@@ -255,7 +228,7 @@ func TestRollupL1UserTxETHCreateAccountDeposit(t *testing.T) {
}
func TestRollupL1UserTxERC20CreateAccountDeposit(t *testing.T) {
rollupClientAux, err := NewRollupClient(ethereumClientAux, hermezRollupAddressConst, tokenHEZAddressConst)
rollupClientAux2, err := NewRollupClient(ethereumClientAux2, hermezRollupAddressConst, tokenHEZ)
require.Nil(t, err)
key := genKeysBjj(1)
fromIdxInt64 := int64(0)
@@ -265,11 +238,11 @@ func TestRollupL1UserTxERC20CreateAccountDeposit(t *testing.T) {
FromIdx: common.Idx(fromIdxInt64),
ToIdx: common.Idx(toIdxInt64),
LoadAmount: big.NewInt(10),
TokenID: common.TokenID(tokenIDERC20),
TokenID: common.TokenID(tokenHEZID),
Amount: big.NewInt(0),
}
_, err = rollupClientAux.RollupL1UserTxERC20ETH(l1Tx.FromBJJ, fromIdxInt64, l1Tx.LoadAmount, l1Tx.Amount, tokenIDERC20, toIdxInt64)
_, err = rollupClientAux2.RollupL1UserTxERC20ETH(l1Tx.FromBJJ, fromIdxInt64, l1Tx.LoadAmount, l1Tx.Amount, tokenHEZID, toIdxInt64)
require.Nil(t, err)
currentBlockNum, _ := rollupClient.client.EthCurrentBlock()
@@ -279,11 +252,11 @@ func TestRollupL1UserTxERC20CreateAccountDeposit(t *testing.T) {
assert.Equal(t, l1Tx.LoadAmount, rollupEvents.L1UserTx[0].L1UserTx.LoadAmount)
assert.Equal(t, l1Tx.TokenID, rollupEvents.L1UserTx[0].L1UserTx.TokenID)
assert.Equal(t, l1Tx.Amount, rollupEvents.L1UserTx[0].L1UserTx.Amount)
assert.Equal(t, rollupClientAux.client.account.Address, rollupEvents.L1UserTx[0].L1UserTx.FromEthAddr)
assert.Equal(t, rollupClientAux2.client.account.Address, rollupEvents.L1UserTx[0].L1UserTx.FromEthAddr)
}
func TestRollupL1UserTxERC777CreateAccountDeposit(t *testing.T) {
rollupClientAux, err := NewRollupClient(ethereumClientAux, hermezRollupAddressConst, tokenHEZAddressConst)
func TestRollupL1UserTxERC20PermitCreateAccountDeposit(t *testing.T) {
rollupClientAux, err := NewRollupClient(ethereumClientAux, hermezRollupAddressConst, tokenHEZ)
require.Nil(t, err)
key := genKeysBjj(3)
fromIdxInt64 := int64(0)
@@ -297,7 +270,7 @@ func TestRollupL1UserTxERC777CreateAccountDeposit(t *testing.T) {
Amount: big.NewInt(0),
}
_, err = rollupClientAux.RollupL1UserTxERC777(l1Tx.FromBJJ, fromIdxInt64, l1Tx.LoadAmount, l1Tx.Amount, tokenIDERC777, toIdxInt64)
_, err = rollupClientAux.RollupL1UserTxERC20Permit(l1Tx.FromBJJ, fromIdxInt64, l1Tx.LoadAmount, l1Tx.Amount, tokenIDERC777, toIdxInt64, deadline)
require.Nil(t, err)
currentBlockNum, _ := rollupClient.client.EthCurrentBlock()
@@ -311,7 +284,7 @@ func TestRollupL1UserTxERC777CreateAccountDeposit(t *testing.T) {
}
func TestRollupL1UserTxETHDeposit(t *testing.T) {
rollupClientAux, err := NewRollupClient(ethereumClientAux, hermezRollupAddressConst, tokenHEZAddressConst)
rollupClientAux, err := NewRollupClient(ethereumClientAux, hermezRollupAddressConst, tokenHEZ)
require.Nil(t, err)
key := genKeysBjj(2)
fromIdxInt64 := int64(0)
@@ -340,7 +313,7 @@ func TestRollupL1UserTxETHDeposit(t *testing.T) {
}
func TestRollupL1UserTxERC20Deposit(t *testing.T) {
rollupClientAux, err := NewRollupClient(ethereumClientAux, hermezRollupAddressConst, tokenHEZAddressConst)
rollupClientAux2, err := NewRollupClient(ethereumClientAux2, hermezRollupAddressConst, tokenHEZ)
require.Nil(t, err)
key := genKeysBjj(1)
fromIdxInt64 := int64(0)
@@ -350,11 +323,11 @@ func TestRollupL1UserTxERC20Deposit(t *testing.T) {
FromIdx: common.Idx(fromIdxInt64),
ToIdx: common.Idx(toIdxInt64),
LoadAmount: big.NewInt(10),
TokenID: common.TokenID(tokenIDERC20),
TokenID: common.TokenID(tokenHEZID),
Amount: big.NewInt(0),
}
_, err = rollupClientAux.RollupL1UserTxERC20ETH(l1Tx.FromBJJ, fromIdxInt64, l1Tx.LoadAmount, l1Tx.Amount, tokenIDERC20, toIdxInt64)
_, err = rollupClientAux2.RollupL1UserTxERC20ETH(l1Tx.FromBJJ, fromIdxInt64, l1Tx.LoadAmount, l1Tx.Amount, tokenHEZID, toIdxInt64)
require.Nil(t, err)
currentBlockNum, _ := rollupClient.client.EthCurrentBlock()
@@ -364,11 +337,11 @@ func TestRollupL1UserTxERC20Deposit(t *testing.T) {
assert.Equal(t, l1Tx.LoadAmount, rollupEvents.L1UserTx[0].L1UserTx.LoadAmount)
assert.Equal(t, l1Tx.TokenID, rollupEvents.L1UserTx[0].L1UserTx.TokenID)
assert.Equal(t, l1Tx.Amount, rollupEvents.L1UserTx[0].L1UserTx.Amount)
assert.Equal(t, rollupClientAux.client.account.Address, rollupEvents.L1UserTx[0].L1UserTx.FromEthAddr)
assert.Equal(t, rollupClientAux2.client.account.Address, rollupEvents.L1UserTx[0].L1UserTx.FromEthAddr)
}
func TestRollupL1UserTxERC777Deposit(t *testing.T) {
rollupClientAux, err := NewRollupClient(ethereumClientAux, hermezRollupAddressConst, tokenHEZAddressConst)
func TestRollupL1UserTxERC20PermitDeposit(t *testing.T) {
rollupClientAux, err := NewRollupClient(ethereumClientAux, hermezRollupAddressConst, tokenHEZ)
require.Nil(t, err)
key := genKeysBjj(3)
fromIdxInt64 := int64(0)
@@ -382,7 +355,7 @@ func TestRollupL1UserTxERC777Deposit(t *testing.T) {
Amount: big.NewInt(0),
}
_, err = rollupClientAux.RollupL1UserTxERC777(l1Tx.FromBJJ, fromIdxInt64, l1Tx.LoadAmount, l1Tx.Amount, tokenIDERC777, toIdxInt64)
_, err = rollupClientAux.RollupL1UserTxERC20Permit(l1Tx.FromBJJ, fromIdxInt64, l1Tx.LoadAmount, l1Tx.Amount, tokenIDERC777, toIdxInt64, deadline)
require.Nil(t, err)
currentBlockNum, _ := rollupClient.client.EthCurrentBlock()
@@ -396,7 +369,7 @@ func TestRollupL1UserTxERC777Deposit(t *testing.T) {
}
func TestRollupL1UserTxETHDepositTransfer(t *testing.T) {
rollupClientAux, err := NewRollupClient(ethereumClientAux, hermezRollupAddressConst, tokenHEZAddressConst)
rollupClientAux, err := NewRollupClient(ethereumClientAux, hermezRollupAddressConst, tokenHEZ)
require.Nil(t, err)
key := genKeysBjj(2)
fromIdxInt64 := int64(0)
@@ -425,7 +398,7 @@ func TestRollupL1UserTxETHDepositTransfer(t *testing.T) {
}
func TestRollupL1UserTxERC20DepositTransfer(t *testing.T) {
rollupClientAux, err := NewRollupClient(ethereumClientAux, hermezRollupAddressConst, tokenHEZAddressConst)
rollupClientAux2, err := NewRollupClient(ethereumClientAux2, hermezRollupAddressConst, tokenHEZ)
require.Nil(t, err)
key := genKeysBjj(1)
fromIdxInt64 := int64(0)
@@ -435,11 +408,11 @@ func TestRollupL1UserTxERC20DepositTransfer(t *testing.T) {
FromIdx: common.Idx(fromIdxInt64),
ToIdx: common.Idx(toIdxInt64),
LoadAmount: big.NewInt(10),
TokenID: common.TokenID(tokenIDERC20),
TokenID: common.TokenID(tokenHEZID),
Amount: big.NewInt(0),
}
_, err = rollupClientAux.RollupL1UserTxERC20ETH(l1Tx.FromBJJ, fromIdxInt64, l1Tx.LoadAmount, l1Tx.Amount, tokenIDERC20, toIdxInt64)
_, err = rollupClientAux2.RollupL1UserTxERC20ETH(l1Tx.FromBJJ, fromIdxInt64, l1Tx.LoadAmount, l1Tx.Amount, tokenHEZID, toIdxInt64)
require.Nil(t, err)
currentBlockNum, _ := rollupClient.client.EthCurrentBlock()
@@ -449,11 +422,11 @@ func TestRollupL1UserTxERC20DepositTransfer(t *testing.T) {
assert.Equal(t, l1Tx.LoadAmount, rollupEvents.L1UserTx[0].L1UserTx.LoadAmount)
assert.Equal(t, l1Tx.TokenID, rollupEvents.L1UserTx[0].L1UserTx.TokenID)
assert.Equal(t, l1Tx.Amount, rollupEvents.L1UserTx[0].L1UserTx.Amount)
assert.Equal(t, rollupClientAux.client.account.Address, rollupEvents.L1UserTx[0].L1UserTx.FromEthAddr)
assert.Equal(t, rollupClientAux2.client.account.Address, rollupEvents.L1UserTx[0].L1UserTx.FromEthAddr)
}
func TestRollupL1UserTxERC777DepositTransfer(t *testing.T) {
rollupClientAux, err := NewRollupClient(ethereumClientAux, hermezRollupAddressConst, tokenHEZAddressConst)
func TestRollupL1UserTxERC20PermitDepositTransfer(t *testing.T) {
rollupClientAux, err := NewRollupClient(ethereumClientAux, hermezRollupAddressConst, tokenHEZ)
require.Nil(t, err)
key := genKeysBjj(3)
fromIdxInt64 := int64(0)
@@ -467,7 +440,7 @@ func TestRollupL1UserTxERC777DepositTransfer(t *testing.T) {
Amount: big.NewInt(0),
}
_, err = rollupClientAux.RollupL1UserTxERC777(l1Tx.FromBJJ, fromIdxInt64, l1Tx.LoadAmount, l1Tx.Amount, tokenIDERC777, toIdxInt64)
_, err = rollupClientAux.RollupL1UserTxERC20Permit(l1Tx.FromBJJ, fromIdxInt64, l1Tx.LoadAmount, l1Tx.Amount, tokenIDERC777, toIdxInt64, deadline)
require.Nil(t, err)
currentBlockNum, _ := rollupClient.client.EthCurrentBlock()
@@ -481,7 +454,7 @@ func TestRollupL1UserTxERC777DepositTransfer(t *testing.T) {
}
func TestRollupL1UserTxETHCreateAccountDepositTransfer(t *testing.T) {
rollupClientAux, err := NewRollupClient(ethereumClientAux, hermezRollupAddressConst, tokenHEZAddressConst)
rollupClientAux, err := NewRollupClient(ethereumClientAux, hermezRollupAddressConst, tokenHEZ)
require.Nil(t, err)
key := genKeysBjj(2)
fromIdxInt64 := int64(0)
@@ -510,7 +483,7 @@ func TestRollupL1UserTxETHCreateAccountDepositTransfer(t *testing.T) {
}
func TestRollupL1UserTxERC20CreateAccountDepositTransfer(t *testing.T) {
rollupClientAux, err := NewRollupClient(ethereumClientAux, hermezRollupAddressConst, tokenHEZAddressConst)
rollupClientAux2, err := NewRollupClient(ethereumClientAux2, hermezRollupAddressConst, tokenHEZ)
require.Nil(t, err)
key := genKeysBjj(1)
fromIdxInt64 := int64(0)
@@ -520,11 +493,11 @@ func TestRollupL1UserTxERC20CreateAccountDepositTransfer(t *testing.T) {
FromIdx: common.Idx(fromIdxInt64),
ToIdx: common.Idx(toIdxInt64),
LoadAmount: big.NewInt(10),
TokenID: common.TokenID(tokenIDERC20),
TokenID: common.TokenID(tokenHEZID),
Amount: big.NewInt(0),
}
_, err = rollupClientAux.RollupL1UserTxERC20ETH(l1Tx.FromBJJ, fromIdxInt64, l1Tx.LoadAmount, l1Tx.Amount, tokenIDERC20, toIdxInt64)
_, err = rollupClientAux2.RollupL1UserTxERC20ETH(l1Tx.FromBJJ, fromIdxInt64, l1Tx.LoadAmount, l1Tx.Amount, tokenHEZID, toIdxInt64)
require.Nil(t, err)
currentBlockNum, _ := rollupClient.client.EthCurrentBlock()
@@ -534,11 +507,11 @@ func TestRollupL1UserTxERC20CreateAccountDepositTransfer(t *testing.T) {
assert.Equal(t, l1Tx.LoadAmount, rollupEvents.L1UserTx[0].L1UserTx.LoadAmount)
assert.Equal(t, l1Tx.TokenID, rollupEvents.L1UserTx[0].L1UserTx.TokenID)
assert.Equal(t, l1Tx.Amount, rollupEvents.L1UserTx[0].L1UserTx.Amount)
assert.Equal(t, rollupClientAux.client.account.Address, rollupEvents.L1UserTx[0].L1UserTx.FromEthAddr)
assert.Equal(t, rollupClientAux2.client.account.Address, rollupEvents.L1UserTx[0].L1UserTx.FromEthAddr)
}
func TestRollupL1UserTxERC777CreateAccountDepositTransfer(t *testing.T) {
rollupClientAux, err := NewRollupClient(ethereumClientAux, hermezRollupAddressConst, tokenHEZAddressConst)
func TestRollupL1UserTxERC20PermitCreateAccountDepositTransfer(t *testing.T) {
rollupClientAux, err := NewRollupClient(ethereumClientAux, hermezRollupAddressConst, tokenHEZ)
require.Nil(t, err)
key := genKeysBjj(3)
fromIdxInt64 := int64(0)
@@ -552,7 +525,7 @@ func TestRollupL1UserTxERC777CreateAccountDepositTransfer(t *testing.T) {
Amount: big.NewInt(0),
}
_, err = rollupClientAux.RollupL1UserTxERC777(l1Tx.FromBJJ, fromIdxInt64, l1Tx.LoadAmount, l1Tx.Amount, tokenIDERC777, toIdxInt64)
_, err = rollupClientAux.RollupL1UserTxERC20Permit(l1Tx.FromBJJ, fromIdxInt64, l1Tx.LoadAmount, l1Tx.Amount, tokenIDERC777, toIdxInt64, deadline)
require.Nil(t, err)
currentBlockNum, _ := rollupClient.client.EthCurrentBlock()
@@ -566,7 +539,7 @@ func TestRollupL1UserTxERC777CreateAccountDepositTransfer(t *testing.T) {
}
func TestRollupL1UserTxETHForceTransfer(t *testing.T) {
rollupClientAux, err := NewRollupClient(ethereumClientAux, hermezRollupAddressConst, tokenHEZAddressConst)
rollupClientAux, err := NewRollupClient(ethereumClientAux, hermezRollupAddressConst, tokenHEZ)
require.Nil(t, err)
key := genKeysBjj(2)
fromIdxInt64 := int64(0)
@@ -595,7 +568,7 @@ func TestRollupL1UserTxETHForceTransfer(t *testing.T) {
}
func TestRollupL1UserTxERC20ForceTransfer(t *testing.T) {
rollupClientAux, err := NewRollupClient(ethereumClientAux, hermezRollupAddressConst, tokenHEZAddressConst)
rollupClientAux2, err := NewRollupClient(ethereumClientAux2, hermezRollupAddressConst, tokenHEZ)
require.Nil(t, err)
key := genKeysBjj(1)
fromIdxInt64 := int64(0)
@@ -605,11 +578,11 @@ func TestRollupL1UserTxERC20ForceTransfer(t *testing.T) {
FromIdx: common.Idx(fromIdxInt64),
ToIdx: common.Idx(toIdxInt64),
LoadAmount: big.NewInt(10),
TokenID: common.TokenID(tokenIDERC20),
TokenID: common.TokenID(tokenHEZID),
Amount: big.NewInt(0),
}
_, err = rollupClientAux.RollupL1UserTxERC20ETH(l1Tx.FromBJJ, fromIdxInt64, l1Tx.LoadAmount, l1Tx.Amount, tokenIDERC20, toIdxInt64)
_, err = rollupClientAux2.RollupL1UserTxERC20ETH(l1Tx.FromBJJ, fromIdxInt64, l1Tx.LoadAmount, l1Tx.Amount, tokenHEZID, toIdxInt64)
require.Nil(t, err)
currentBlockNum, _ := rollupClient.client.EthCurrentBlock()
@@ -619,11 +592,11 @@ func TestRollupL1UserTxERC20ForceTransfer(t *testing.T) {
assert.Equal(t, l1Tx.LoadAmount, rollupEvents.L1UserTx[0].L1UserTx.LoadAmount)
assert.Equal(t, l1Tx.TokenID, rollupEvents.L1UserTx[0].L1UserTx.TokenID)
assert.Equal(t, l1Tx.Amount, rollupEvents.L1UserTx[0].L1UserTx.Amount)
assert.Equal(t, rollupClientAux.client.account.Address, rollupEvents.L1UserTx[0].L1UserTx.FromEthAddr)
assert.Equal(t, rollupClientAux2.client.account.Address, rollupEvents.L1UserTx[0].L1UserTx.FromEthAddr)
}
func TestRollupL1UserTxERC777ForceTransfer(t *testing.T) {
rollupClientAux, err := NewRollupClient(ethereumClientAux, hermezRollupAddressConst, tokenHEZAddressConst)
func TestRollupL1UserTxERC20PermitForceTransfer(t *testing.T) {
rollupClientAux, err := NewRollupClient(ethereumClientAux, hermezRollupAddressConst, tokenHEZ)
require.Nil(t, err)
key := genKeysBjj(3)
fromIdxInt64 := int64(0)
@@ -637,7 +610,7 @@ func TestRollupL1UserTxERC777ForceTransfer(t *testing.T) {
Amount: big.NewInt(0),
}
_, err = rollupClientAux.RollupL1UserTxERC777(l1Tx.FromBJJ, fromIdxInt64, l1Tx.LoadAmount, l1Tx.Amount, tokenIDERC777, toIdxInt64)
_, err = rollupClientAux.RollupL1UserTxERC20Permit(l1Tx.FromBJJ, fromIdxInt64, l1Tx.LoadAmount, l1Tx.Amount, tokenIDERC777, toIdxInt64, deadline)
require.Nil(t, err)
currentBlockNum, _ := rollupClient.client.EthCurrentBlock()
@@ -651,7 +624,7 @@ func TestRollupL1UserTxERC777ForceTransfer(t *testing.T) {
}
func TestRollupL1UserTxETHForceExit(t *testing.T) {
rollupClientAux, err := NewRollupClient(ethereumClientAux, hermezRollupAddressConst, tokenHEZAddressConst)
rollupClientAux, err := NewRollupClient(ethereumClientAux, hermezRollupAddressConst, tokenHEZ)
require.Nil(t, err)
key := genKeysBjj(2)
fromIdxInt64 := int64(0)
@@ -680,7 +653,7 @@ func TestRollupL1UserTxETHForceExit(t *testing.T) {
}
func TestRollupL1UserTxERC20ForceExit(t *testing.T) {
rollupClientAux, err := NewRollupClient(ethereumClientAux, hermezRollupAddressConst, tokenHEZAddressConst)
rollupClientAux2, err := NewRollupClient(ethereumClientAux2, hermezRollupAddressConst, tokenHEZ)
require.Nil(t, err)
key := genKeysBjj(1)
fromIdxInt64 := int64(0)
@@ -690,11 +663,11 @@ func TestRollupL1UserTxERC20ForceExit(t *testing.T) {
FromIdx: common.Idx(fromIdxInt64),
ToIdx: common.Idx(toIdxInt64),
LoadAmount: big.NewInt(10),
TokenID: common.TokenID(tokenIDERC20),
TokenID: common.TokenID(tokenHEZID),
Amount: big.NewInt(0),
}
_, err = rollupClientAux.RollupL1UserTxERC20ETH(l1Tx.FromBJJ, fromIdxInt64, l1Tx.LoadAmount, l1Tx.Amount, tokenIDERC20, toIdxInt64)
_, err = rollupClientAux2.RollupL1UserTxERC20ETH(l1Tx.FromBJJ, fromIdxInt64, l1Tx.LoadAmount, l1Tx.Amount, tokenHEZID, toIdxInt64)
require.Nil(t, err)
currentBlockNum, _ := rollupClient.client.EthCurrentBlock()
@@ -704,11 +677,11 @@ func TestRollupL1UserTxERC20ForceExit(t *testing.T) {
assert.Equal(t, l1Tx.LoadAmount, rollupEvents.L1UserTx[0].L1UserTx.LoadAmount)
assert.Equal(t, l1Tx.TokenID, rollupEvents.L1UserTx[0].L1UserTx.TokenID)
assert.Equal(t, l1Tx.Amount, rollupEvents.L1UserTx[0].L1UserTx.Amount)
assert.Equal(t, rollupClientAux.client.account.Address, rollupEvents.L1UserTx[0].L1UserTx.FromEthAddr)
assert.Equal(t, rollupClientAux2.client.account.Address, rollupEvents.L1UserTx[0].L1UserTx.FromEthAddr)
}
func TestRollupL1UserTxERC777ForceExit(t *testing.T) {
rollupClientAux, err := NewRollupClient(ethereumClientAux, hermezRollupAddressConst, tokenHEZAddressConst)
func TestRollupL1UserTxERC20PermitForceExit(t *testing.T) {
rollupClientAux, err := NewRollupClient(ethereumClientAux, hermezRollupAddressConst, tokenHEZ)
require.Nil(t, err)
key := genKeysBjj(3)
fromIdxInt64 := int64(0)
@@ -724,7 +697,7 @@ func TestRollupL1UserTxERC777ForceExit(t *testing.T) {
Amount: big.NewInt(0),
}
_, err = rollupClientAux.RollupL1UserTxERC777(l1Tx.FromBJJ, fromIdxInt64, l1Tx.LoadAmount, l1Tx.Amount, tokenIDERC777, toIdxInt64)
_, err = rollupClientAux.RollupL1UserTxERC20Permit(l1Tx.FromBJJ, fromIdxInt64, l1Tx.LoadAmount, l1Tx.Amount, tokenIDERC777, toIdxInt64, deadline)
require.Nil(t, err)
currentBlockNum, _ := rollupClient.client.EthCurrentBlock()
@@ -783,7 +756,7 @@ func TestRollupForgeBatch2(t *testing.T) {
}
func TestRollupWithdrawMerkleProof(t *testing.T) {
rollupClientAux, err := NewRollupClient(ethereumClientAux, hermezRollupAddressConst, tokenHEZAddressConst)
rollupClientAux, err := NewRollupClient(ethereumClientAux, hermezRollupAddressConst, tokenHEZ)
require.Nil(t, err)
var pkComp babyjub.PublicKeyComp

View File

@@ -117,19 +117,19 @@ func TestWDelayerDeposit(t *testing.T) {
amount.SetString("1100000000000000000", 10)
wdelayerClientHermez, err := NewWDelayerClient(ethereumClientHermez, wdelayerTestAddressConst)
require.Nil(t, err)
_, err = wdelayerClientHermez.WDelayerDeposit(auxAddressConst, tokenERC20AddressConst, amount)
_, err = wdelayerClientHermez.WDelayerDeposit(auxAddressConst, tokenHEZAddressConst, amount)
require.Nil(t, err)
currentBlockNum, _ := wdelayerClientTest.client.EthCurrentBlock()
wdelayerEvents, _, _ := wdelayerClientTest.WDelayerEventsByBlock(currentBlockNum)
assert.Equal(t, amount, wdelayerEvents.Deposit[0].Amount)
assert.Equal(t, auxAddressConst, wdelayerEvents.Deposit[0].Owner)
assert.Equal(t, tokenERC20AddressConst, wdelayerEvents.Deposit[0].Token)
assert.Equal(t, tokenHEZAddressConst, wdelayerEvents.Deposit[0].Token)
}
func TestWDelayerDepositInfo(t *testing.T) {
amount := new(big.Int)
amount.SetString("1100000000000000000", 10)
state, err := wdelayerClientTest.WDelayerDepositInfo(auxAddressConst, tokenERC20AddressConst)
state, err := wdelayerClientTest.WDelayerDepositInfo(auxAddressConst, tokenHEZAddressConst)
require.Nil(t, err)
assert.Equal(t, state.Amount, amount)
}
@@ -137,16 +137,16 @@ func TestWDelayerDepositInfo(t *testing.T) {
func TestWDelayerWithdrawal(t *testing.T) {
amount := new(big.Int)
amount.SetString("1100000000000000000", 10)
_, err := wdelayerClientTest.WDelayerWithdrawal(auxAddressConst, tokenERC20AddressConst)
require.Contains(t, err.Error(), "Withdrawal not allowed yet")
_, err := wdelayerClientTest.WDelayerWithdrawal(auxAddressConst, tokenHEZAddressConst)
require.Contains(t, err.Error(), "WITHDRAWAL_NOT_ALLOWED")
addBlocks(newWithdrawalDelay.Int64(), ethClientDialURL)
_, err = wdelayerClientTest.WDelayerWithdrawal(auxAddressConst, tokenERC20AddressConst)
_, err = wdelayerClientTest.WDelayerWithdrawal(auxAddressConst, tokenHEZAddressConst)
require.Nil(t, err)
currentBlockNum, _ := wdelayerClientTest.client.EthCurrentBlock()
wdelayerEvents, _, _ := wdelayerClientTest.WDelayerEventsByBlock(currentBlockNum)
assert.Equal(t, amount, wdelayerEvents.Withdraw[0].Amount)
assert.Equal(t, auxAddressConst, wdelayerEvents.Withdraw[0].Owner)
assert.Equal(t, tokenERC20AddressConst, wdelayerEvents.Withdraw[0].Token)
assert.Equal(t, tokenHEZAddressConst, wdelayerEvents.Withdraw[0].Token)
}
func TestWDelayerSecondDeposit(t *testing.T) {
@@ -154,13 +154,13 @@ func TestWDelayerSecondDeposit(t *testing.T) {
amount.SetString("1100000000000000000", 10)
wdelayerClientHermez, err := NewWDelayerClient(ethereumClientHermez, wdelayerTestAddressConst)
require.Nil(t, err)
_, err = wdelayerClientHermez.WDelayerDeposit(auxAddressConst, tokenERC20AddressConst, amount)
_, err = wdelayerClientHermez.WDelayerDeposit(auxAddressConst, tokenHEZAddressConst, amount)
require.Nil(t, err)
currentBlockNum, _ := wdelayerClientTest.client.EthCurrentBlock()
wdelayerEvents, _, _ := wdelayerClientTest.WDelayerEventsByBlock(currentBlockNum)
assert.Equal(t, amount, wdelayerEvents.Deposit[0].Amount)
assert.Equal(t, auxAddressConst, wdelayerEvents.Deposit[0].Owner)
assert.Equal(t, tokenERC20AddressConst, wdelayerEvents.Deposit[0].Token)
assert.Equal(t, tokenHEZAddressConst, wdelayerEvents.Deposit[0].Token)
}
func TestWDelayerEnableEmergencyMode(t *testing.T) {
@@ -192,15 +192,15 @@ func TestWDelayerEscapeHatchWithdrawal(t *testing.T) {
amount.SetString("10000000000000000", 10)
wdelayerClientWhite, err := NewWDelayerClient(ethereumClientWhite, wdelayerTestAddressConst)
require.Nil(t, err)
_, err = wdelayerClientWhite.WDelayerEscapeHatchWithdrawal(governanceAddressConst, tokenERC20AddressConst, amount)
require.Contains(t, err.Error(), "NO MAX_EMERGENCY_MODE_TIME")
_, err = wdelayerClientWhite.WDelayerEscapeHatchWithdrawal(governanceAddressConst, tokenHEZAddressConst, amount)
require.Contains(t, err.Error(), "NO_MAX_EMERGENCY_MODE_TIME")
seconds := maxEmergencyModeTime.Seconds()
addTime(seconds, ethClientDialURL)
_, err = wdelayerClientWhite.WDelayerEscapeHatchWithdrawal(governanceAddressConst, tokenERC20AddressConst, amount)
_, err = wdelayerClientWhite.WDelayerEscapeHatchWithdrawal(governanceAddressConst, tokenHEZAddressConst, amount)
require.Nil(t, err)
currentBlockNum, _ := wdelayerClientTest.client.EthCurrentBlock()
wdelayerEvents, _, _ := wdelayerClientTest.WDelayerEventsByBlock(currentBlockNum)
assert.Equal(t, tokenERC20AddressConst, wdelayerEvents.EscapeHatchWithdrawal[0].Token)
assert.Equal(t, tokenHEZAddressConst, wdelayerEvents.EscapeHatchWithdrawal[0].Token)
assert.Equal(t, governanceAddressConst, wdelayerEvents.EscapeHatchWithdrawal[0].To)
assert.Equal(t, whiteHackGroupAddressConst, wdelayerEvents.EscapeHatchWithdrawal[0].Who)
assert.Equal(t, amount, wdelayerEvents.EscapeHatchWithdrawal[0].Amount)

1
go.mod
View File

@@ -16,6 +16,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/mattn/go-sqlite3 v2.0.3+incompatible
github.com/mitchellh/copystructure v1.0.0

1
go.sum
View File

@@ -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=

View File

@@ -96,8 +96,11 @@ func NewNode(mode Mode, cfg *config.Node, coordCfg *config.Coordinator) (*Node,
Address: cfg.SmartContracts.Rollup,
},
Auction: eth.AuctionConfig{
Address: cfg.SmartContracts.Auction,
TokenHEZAddress: cfg.SmartContracts.TokenHEZ,
Address: cfg.SmartContracts.Auction,
TokenHEZ: eth.TokenConfig{
Address: cfg.SmartContracts.TokenHEZ,
Name: cfg.SmartContracts.TokenHEZName,
},
},
})
if err != nil {

View File

@@ -146,7 +146,7 @@ func TestSync(t *testing.T) {
// Add tokens to ethereum, and to rollup
for _, token := range tokens {
client.CtlAddERC20(token.Addr, token.Consts)
_, err := client.RollupAddToken(token.Addr, clientSetup.RollupVariables.FeeAddToken)
_, err := client.RollupAddTokenSimple(token.Addr, clientSetup.RollupVariables.FeeAddToken)
require.Nil(t, err)
}

View File

@@ -621,6 +621,12 @@ var errTODO = fmt.Errorf("TODO: Not implemented yet")
// })
// }
// RollupL1UserTxERC20Permit is the interface to call the smart contract function
func (c *Client) RollupL1UserTxERC20Permit(fromBJJ *babyjub.PublicKey, fromIdx int64, loadAmount *big.Int, amount *big.Int, tokenID uint32, toIdx int64, deadline *big.Int) (tx *types.Transaction, err error) {
log.Error("TODO")
return nil, errTODO
}
// RollupL1UserTxERC20ETH sends an L1UserTx to the Rollup.
func (c *Client) RollupL1UserTxERC20ETH(
fromBJJ *babyjub.PublicKey,
@@ -683,10 +689,10 @@ func (c *Client) RollupL1UserTxERC20ETH(
}
// RollupL1UserTxERC777 is the interface to call the smart contract function
func (c *Client) RollupL1UserTxERC777(fromBJJ *babyjub.PublicKey, fromIdx int64, loadAmount *big.Int, amount *big.Int, tokenID uint32, toIdx int64) (*types.Transaction, error) {
log.Error("TODO")
return nil, errTODO
}
// func (c *Client) RollupL1UserTxERC777(fromBJJ *babyjub.PublicKey, fromIdx int64, loadAmount *big.Int, amount *big.Int, tokenID uint32, toIdx int64) (*types.Transaction, error) {
// log.Error("TODO")
// return nil, errTODO
// }
// RollupRegisterTokensCount is the interface to call the smart contract function
func (c *Client) RollupRegisterTokensCount() (*big.Int, error) {
@@ -790,8 +796,15 @@ func (c *Client) addBatch(args *eth.RollupForgeBatchArgs) (*types.Transaction, e
return ethTx, nil
}
// RollupAddTokenSimple is a wrapper around RollupAddToken that automatically
// sets `deadlie`.
func (c *Client) RollupAddTokenSimple(tokenAddress ethCommon.Address, feeAddToken *big.Int) (tx *types.Transaction, err error) {
return c.RollupAddToken(tokenAddress, feeAddToken, big.NewInt(9999)) //nolint:gomnd
}
// RollupAddToken is the interface to call the smart contract function
func (c *Client) RollupAddToken(tokenAddress ethCommon.Address, feeAddToken *big.Int) (tx *types.Transaction, err error) {
func (c *Client) RollupAddToken(tokenAddress ethCommon.Address, feeAddToken *big.Int,
deadline *big.Int) (tx *types.Transaction, err error) {
c.rw.Lock()
defer c.rw.Unlock()
cpy := c.nextBlock().copy()
@@ -1190,8 +1203,15 @@ func (c *Client) AuctionGetSlotSet(slot int64) (*big.Int, error) {
// return errTODO
// }
// AuctionBid is the interface to call the smart contract function
func (c *Client) AuctionBid(slot int64, bidAmount *big.Int) (tx *types.Transaction, err error) {
// AuctionBidSimple is a wrapper around AuctionBid that automatically sets `amount` and `deadline`.
func (c *Client) AuctionBidSimple(slot int64, bidAmount *big.Int) (tx *types.Transaction, err error) {
return c.AuctionBid(bidAmount, slot, bidAmount, big.NewInt(99999)) //nolint:gomnd
}
// AuctionBid is the interface to call the smart contract function. This
// implementation behaves as if any address has infinite tokens.
func (c *Client) AuctionBid(amount *big.Int, slot int64, bidAmount *big.Int,
deadline *big.Int) (tx *types.Transaction, err error) {
c.rw.Lock()
defer c.rw.Unlock()
cpy := c.nextBlock().copy()
@@ -1242,8 +1262,10 @@ func (c *Client) AuctionBid(slot int64, bidAmount *big.Int) (tx *types.Transacti
return a.addTransaction(newTransaction("bid", data{slot, bidAmount, *c.addr})), nil
}
// AuctionMultiBid is the interface to call the smart contract function
func (c *Client) AuctionMultiBid(startingSlot int64, endingSlot int64, slotSet [6]bool, maxBid, closedMinBid, budget *big.Int) (tx *types.Transaction, err error) {
// AuctionMultiBid is the interface to call the smart contract function. This
// implementation behaves as if any address has infinite tokens.
func (c *Client) AuctionMultiBid(amount *big.Int, startingSlot int64, endingSlot int64, slotSet [6]bool,
maxBid, closedMinBid, deadline *big.Int) (tx *types.Transaction, err error) {
c.rw.Lock()
defer c.rw.Unlock()
cpy := c.nextBlock().copy()

View File

@@ -94,34 +94,34 @@ func TestClientAuction(t *testing.T) {
// Check several cases in which bid doesn't succed, and also do 2 successful bids.
_, err := c.AuctionBid(0, big.NewInt(1))
_, err := c.AuctionBidSimple(0, big.NewInt(1))
assert.Equal(t, errBidClosed, err)
_, err = c.AuctionBid(4322, big.NewInt(1))
_, err = c.AuctionBidSimple(4322, big.NewInt(1))
assert.Equal(t, errBidNotOpen, err)
// 101 % 6 = 5; defaultSlotSetBid[5] = 1500; 1500 + 10% = 1650
_, err = c.AuctionBid(101, big.NewInt(1650))
_, err = c.AuctionBidSimple(101, big.NewInt(1650))
assert.Equal(t, errCoordNotReg, err)
_, err = c.AuctionSetCoordinator(addrForge, "https://foo.bar")
assert.Nil(t, err)
_, err = c.AuctionBid(3, big.NewInt(1))
_, err = c.AuctionBidSimple(3, big.NewInt(1))
assert.Equal(t, errBidBelowMin, err)
_, err = c.AuctionBid(3, big.NewInt(1650))
_, err = c.AuctionBidSimple(3, big.NewInt(1650))
assert.Nil(t, err)
c.CtlSetAddr(addrBidder2)
_, err = c.AuctionSetCoordinator(addrForge2, "https://foo2.bar")
assert.Nil(t, err)
_, err = c.AuctionBid(3, big.NewInt(16))
_, err = c.AuctionBidSimple(3, big.NewInt(16))
assert.Equal(t, errBidBelowMin, err)
// 1650 + 10% = 1815
_, err = c.AuctionBid(3, big.NewInt(1815))
_, err = c.AuctionBidSimple(3, big.NewInt(1815))
assert.Nil(t, err)
c.CtlMineBlock()
@@ -143,7 +143,7 @@ func TestClientRollup(t *testing.T) {
// Add a token
tx, err := c.RollupAddToken(token1Addr, clientSetup.RollupVariables.FeeAddToken)
tx, err := c.RollupAddTokenSimple(token1Addr, clientSetup.RollupVariables.FeeAddToken)
require.Nil(t, err)
assert.NotNil(t, tx)