mirror of
https://github.com/arnaucube/hermez-node.git
synced 2026-02-07 11:26:44 +01:00
Update test.Client, replace some big.Int by int/int64 in eth, fix lints
This commit is contained in:
@@ -5,7 +5,6 @@ import (
|
||||
"math/big"
|
||||
|
||||
"github.com/ethereum/go-ethereum/accounts/abi/bind"
|
||||
"github.com/ethereum/go-ethereum/common"
|
||||
ethCommon "github.com/ethereum/go-ethereum/common"
|
||||
"github.com/ethereum/go-ethereum/core/types"
|
||||
"github.com/ethereum/go-ethereum/ethclient"
|
||||
@@ -57,9 +56,9 @@ type Coordinator struct {
|
||||
// AuctionVariables are the variables of the Auction Smart Contract
|
||||
type AuctionVariables struct {
|
||||
// Boot Coordinator Address
|
||||
DonationAddress *ethCommon.Address
|
||||
DonationAddress ethCommon.Address
|
||||
// Boot Coordinator Address
|
||||
BootCoordinator *ethCommon.Address
|
||||
BootCoordinator ethCommon.Address
|
||||
// The minimum bid value in a series of 6 slots
|
||||
DefaultSlotSetBid [6]*big.Int
|
||||
// Distance (#slots) to the closest slot to which you can bid ( 2 Slots = 2 * 40 Blocks = 20 min )
|
||||
@@ -246,11 +245,11 @@ type AuctionInterface interface {
|
||||
maxBid, closedMinBid, budget *big.Int, forger ethCommon.Address) (*types.Transaction, error)
|
||||
|
||||
// Forge
|
||||
AuctionCanForge(forger ethCommon.Address, blockNumber *big.Int) (bool, error)
|
||||
AuctionCanForge(forger ethCommon.Address, blockNum int64) (bool, error)
|
||||
// AuctionForge(forger ethCommon.Address) (bool, error) // Only called from another smart contract
|
||||
|
||||
// Fees
|
||||
AuctionClaimHEZ(claimAddress common.Address) (*types.Transaction, error)
|
||||
AuctionClaimHEZ(claimAddress ethCommon.Address) (*types.Transaction, error)
|
||||
|
||||
//
|
||||
// Smart Contract Status
|
||||
@@ -266,15 +265,17 @@ 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
|
||||
client *EthereumClient
|
||||
address ethCommon.Address
|
||||
gasLimit uint64
|
||||
}
|
||||
|
||||
// NewAuctionClient creates a new AuctionClient
|
||||
func NewAuctionClient(client *EthereumClient, address ethCommon.Address) *AuctionClient {
|
||||
return &AuctionClient{
|
||||
client: client,
|
||||
address: address,
|
||||
client: client,
|
||||
address: address,
|
||||
gasLimit: 1000000, //nolint:gomnd
|
||||
}
|
||||
}
|
||||
|
||||
@@ -283,7 +284,7 @@ func (c *AuctionClient) AuctionSetSlotDeadline(newDeadline uint8) (*types.Transa
|
||||
var tx *types.Transaction
|
||||
var err error
|
||||
if tx, err = c.client.CallAuth(
|
||||
1000000,
|
||||
c.gasLimit,
|
||||
func(ec *ethclient.Client, auth *bind.TransactOpts) (*types.Transaction, error) {
|
||||
auction, err := HermezAuctionProtocol.NewHermezAuctionProtocol(c.address, ec)
|
||||
if err != nil {
|
||||
@@ -318,7 +319,7 @@ func (c *AuctionClient) AuctionSetOpenAuctionSlots(newOpenAuctionSlots uint16) (
|
||||
var tx *types.Transaction
|
||||
var err error
|
||||
if tx, err = c.client.CallAuth(
|
||||
1000000,
|
||||
c.gasLimit,
|
||||
func(ec *ethclient.Client, auth *bind.TransactOpts) (*types.Transaction, error) {
|
||||
auction, err := HermezAuctionProtocol.NewHermezAuctionProtocol(c.address, ec)
|
||||
if err != nil {
|
||||
@@ -353,7 +354,7 @@ func (c *AuctionClient) AuctionSetClosedAuctionSlots(newClosedAuctionSlots uint1
|
||||
var tx *types.Transaction
|
||||
var err error
|
||||
if tx, err = c.client.CallAuth(
|
||||
1000000,
|
||||
c.gasLimit,
|
||||
func(ec *ethclient.Client, auth *bind.TransactOpts) (*types.Transaction, error) {
|
||||
auction, err := HermezAuctionProtocol.NewHermezAuctionProtocol(c.address, ec)
|
||||
if err != nil {
|
||||
@@ -388,7 +389,7 @@ func (c *AuctionClient) AuctionSetOutbidding(newOutbidding uint16) (*types.Trans
|
||||
var tx *types.Transaction
|
||||
var err error
|
||||
if tx, err = c.client.CallAuth(
|
||||
12500000,
|
||||
12500000, //nolint:gomnd
|
||||
func(ec *ethclient.Client, auth *bind.TransactOpts) (*types.Transaction, error) {
|
||||
auction, err := HermezAuctionProtocol.NewHermezAuctionProtocol(c.address, ec)
|
||||
if err != nil {
|
||||
@@ -423,7 +424,7 @@ func (c *AuctionClient) AuctionSetAllocationRatio(newAllocationRatio [3]uint16)
|
||||
var tx *types.Transaction
|
||||
var err error
|
||||
if tx, err = c.client.CallAuth(
|
||||
1000000,
|
||||
c.gasLimit,
|
||||
func(ec *ethclient.Client, auth *bind.TransactOpts) (*types.Transaction, error) {
|
||||
auction, err := HermezAuctionProtocol.NewHermezAuctionProtocol(c.address, ec)
|
||||
if err != nil {
|
||||
@@ -458,7 +459,7 @@ func (c *AuctionClient) AuctionSetDonationAddress(newDonationAddress ethCommon.A
|
||||
var tx *types.Transaction
|
||||
var err error
|
||||
if tx, err = c.client.CallAuth(
|
||||
1000000,
|
||||
c.gasLimit,
|
||||
func(ec *ethclient.Client, auth *bind.TransactOpts) (*types.Transaction, error) {
|
||||
auction, err := HermezAuctionProtocol.NewHermezAuctionProtocol(c.address, ec)
|
||||
if err != nil {
|
||||
@@ -493,7 +494,7 @@ func (c *AuctionClient) AuctionSetBootCoordinator(newBootCoordinator ethCommon.A
|
||||
var tx *types.Transaction
|
||||
var err error
|
||||
if tx, err = c.client.CallAuth(
|
||||
1000000,
|
||||
c.gasLimit,
|
||||
func(ec *ethclient.Client, auth *bind.TransactOpts) (*types.Transaction, error) {
|
||||
auction, err := HermezAuctionProtocol.NewHermezAuctionProtocol(c.address, ec)
|
||||
if err != nil {
|
||||
@@ -528,7 +529,7 @@ func (c *AuctionClient) AuctionChangeDefaultSlotSetBid(slotSet int64, newInitial
|
||||
var tx *types.Transaction
|
||||
var err error
|
||||
if tx, err = c.client.CallAuth(
|
||||
1000000,
|
||||
c.gasLimit,
|
||||
func(ec *ethclient.Client, auth *bind.TransactOpts) (*types.Transaction, error) {
|
||||
auction, err := HermezAuctionProtocol.NewHermezAuctionProtocol(c.address, ec)
|
||||
if err != nil {
|
||||
@@ -548,7 +549,7 @@ func (c *AuctionClient) AuctionRegisterCoordinator(forgerAddress ethCommon.Addre
|
||||
var tx *types.Transaction
|
||||
var err error
|
||||
if tx, err = c.client.CallAuth(
|
||||
1000000,
|
||||
c.gasLimit,
|
||||
func(ec *ethclient.Client, auth *bind.TransactOpts) (*types.Transaction, error) {
|
||||
auction, err := HermezAuctionProtocol.NewHermezAuctionProtocol(c.address, ec)
|
||||
if err != nil {
|
||||
@@ -583,7 +584,7 @@ func (c *AuctionClient) AuctionUpdateCoordinatorInfo(forgerAddress ethCommon.Add
|
||||
var tx *types.Transaction
|
||||
var err error
|
||||
if tx, err = c.client.CallAuth(
|
||||
1000000,
|
||||
c.gasLimit,
|
||||
func(ec *ethclient.Client, auth *bind.TransactOpts) (*types.Transaction, error) {
|
||||
auction, err := HermezAuctionProtocol.NewHermezAuctionProtocol(c.address, ec)
|
||||
if err != nil {
|
||||
@@ -665,14 +666,14 @@ func (c *AuctionClient) AuctionMultiBid(startingSlot int64, endingSlot int64, sl
|
||||
}
|
||||
|
||||
// AuctionCanForge is the interface to call the smart contract function
|
||||
func (c *AuctionClient) AuctionCanForge(forger ethCommon.Address, blockNumber *big.Int) (bool, error) {
|
||||
func (c *AuctionClient) AuctionCanForge(forger ethCommon.Address, blockNum int64) (bool, error) {
|
||||
var canForge bool
|
||||
if err := c.client.Call(func(ec *ethclient.Client) error {
|
||||
auction, err := HermezAuctionProtocol.NewHermezAuctionProtocol(c.address, ec)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
canForge, err = auction.CanForge(nil, forger, blockNumber)
|
||||
canForge, err = auction.CanForge(nil, forger, big.NewInt(blockNum))
|
||||
return err
|
||||
}); err != nil {
|
||||
return false, err
|
||||
@@ -686,11 +687,11 @@ func (c *AuctionClient) AuctionCanForge(forger ethCommon.Address, blockNumber *b
|
||||
// }
|
||||
|
||||
// AuctionClaimHEZ is the interface to call the smart contract function
|
||||
func (c *AuctionClient) AuctionClaimHEZ(claimAddress common.Address) (*types.Transaction, error) {
|
||||
func (c *AuctionClient) AuctionClaimHEZ(claimAddress ethCommon.Address) (*types.Transaction, error) {
|
||||
var tx *types.Transaction
|
||||
var err error
|
||||
if tx, err = c.client.CallAuth(
|
||||
1000000,
|
||||
c.gasLimit,
|
||||
func(ec *ethclient.Client, auth *bind.TransactOpts) (*types.Transaction, error) {
|
||||
auction, err := HermezAuctionProtocol.NewHermezAuctionProtocol(c.address, ec)
|
||||
if err != nil {
|
||||
@@ -713,10 +714,22 @@ func (c *AuctionClient) AuctionConstants() (*AuctionConstants, error) {
|
||||
return err
|
||||
}
|
||||
auctionConstants.BlocksPerSlot, err = auction.BLOCKSPERSLOT(nil)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
genesisBlock, err := auction.GenesisBlock(nil)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
auctionConstants.GenesisBlockNum = genesisBlock.Int64()
|
||||
auctionConstants.HermezRollup, err = auction.HermezRollup(nil)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
auctionConstants.InitialMinimalBidding, err = auction.INITIALMINIMALBIDDING(nil)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
auctionConstants.TokenHEZ, err = auction.TokenHEZ(nil)
|
||||
return err
|
||||
}); err != nil {
|
||||
@@ -731,8 +744,18 @@ func (c *AuctionClient) AuctionVariables() (*AuctionVariables, error) {
|
||||
if err := c.client.Call(func(ec *ethclient.Client) error {
|
||||
var err error
|
||||
auctionVariables.AllocationRatio, err = c.AuctionGetAllocationRatio()
|
||||
auctionVariables.BootCoordinator, err = c.AuctionGetBootCoordinator()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
bootCoordinator, err := c.AuctionGetBootCoordinator()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
auctionVariables.BootCoordinator = *bootCoordinator
|
||||
auctionVariables.ClosedAuctionSlots, err = c.AuctionGetClosedAuctionSlots()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
var defaultSlotSetBid [6]*big.Int
|
||||
for i := uint8(0); i < 6; i++ {
|
||||
bid, err := c.AuctionGetDefaultSlotSetBid(i)
|
||||
@@ -742,9 +765,19 @@ func (c *AuctionClient) AuctionVariables() (*AuctionVariables, error) {
|
||||
defaultSlotSetBid[i] = bid
|
||||
}
|
||||
auctionVariables.DefaultSlotSetBid = defaultSlotSetBid
|
||||
auctionVariables.DonationAddress, err = c.AuctionGetDonationAddress()
|
||||
donationAddress, err := c.AuctionGetDonationAddress()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
auctionVariables.DonationAddress = *donationAddress
|
||||
auctionVariables.OpenAuctionSlots, err = c.AuctionGetOpenAuctionSlots()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
auctionVariables.Outbidding, err = c.AuctionGetOutbidding()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
auctionVariables.SlotDeadline, err = c.AuctionGetSlotDeadline()
|
||||
return err
|
||||
}); err != nil {
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package eth
|
||||
|
||||
import (
|
||||
"io/ioutil"
|
||||
"math/big"
|
||||
"os"
|
||||
"testing"
|
||||
@@ -36,7 +37,8 @@ var BOOTCOORDINATOR = common.HexToAddress(bootCoordinatorStr)
|
||||
|
||||
var ehtClientDialURL = "http://localhost:8545"
|
||||
var auctionAddressStr = "0x3619DbE27d7c1e7E91aA738697Ae7Bc5FC3eACA5"
|
||||
var ownerAddressStr = "0xc783df8a850f42e7F7e57013759C285caa701eB6"
|
||||
|
||||
// var ownerAddressStr = "0xc783df8a850f42e7F7e57013759C285caa701eB6"
|
||||
var governanceAddressStr = "0xead9c93b79ae7c1591b1fb5323bd777e86e150d4"
|
||||
var governancePrivateKey = "d49743deccbccc5dc7baa8e69e5be03298da8688a15dd202e20f15d5e0e9a9fb"
|
||||
var minBidStr = "10000000000000000000"
|
||||
@@ -46,15 +48,18 @@ var BLOCKSPERSLOT = uint8(40)
|
||||
var TOKENHEZ = common.HexToAddress("0xf4e77E5Da47AC3125140c470c71cBca77B5c638c")
|
||||
var HERMEZROLLUP = common.HexToAddress("0xc4905364b78a742ccce7B890A89514061E47068D")
|
||||
|
||||
var pathKs = "test/ks"
|
||||
var password = "pass"
|
||||
|
||||
func TestNewAction(t *testing.T) {
|
||||
key, err := crypto.HexToECDSA(governancePrivateKey)
|
||||
require.Nil(t, err)
|
||||
ks := keystore.NewKeyStore(pathKs, keystore.StandardScryptN, keystore.StandardScryptP)
|
||||
dir, err := ioutil.TempDir("", "tmpks")
|
||||
require.Nil(t, err)
|
||||
ks := keystore.NewKeyStore(dir, keystore.StandardScryptN, keystore.StandardScryptP)
|
||||
account, err := ks.ImportECDSA(key, password)
|
||||
ks.Unlock(account, password)
|
||||
require.Nil(t, err)
|
||||
err = ks.Unlock(account, password)
|
||||
require.Nil(t, err)
|
||||
// Init eth client
|
||||
ethClient, err := ethclient.Dial(ehtClientDialURL)
|
||||
require.Nil(t, err)
|
||||
@@ -120,6 +125,7 @@ func TestAuctionSetSlotDeadline(t *testing.T) {
|
||||
_, err := auctionClient.AuctionSetSlotDeadline(newSlotDeadline)
|
||||
require.Nil(t, err)
|
||||
slotDeadline, err := auctionClient.AuctionGetSlotDeadline()
|
||||
require.Nil(t, err)
|
||||
assert.Equal(t, newSlotDeadline, slotDeadline)
|
||||
_, err = auctionClient.AuctionSetSlotDeadline(slotDeadlineConst)
|
||||
require.Nil(t, err)
|
||||
@@ -140,6 +146,7 @@ func TestAuctionSetOpenAuctionSlots(t *testing.T) {
|
||||
_, err := auctionClient.AuctionSetOpenAuctionSlots(newOpenAuctionSlots)
|
||||
require.Nil(t, err)
|
||||
openAuctionSlots, err := auctionClient.AuctionGetOpenAuctionSlots()
|
||||
require.Nil(t, err)
|
||||
assert.Equal(t, newOpenAuctionSlots, openAuctionSlots)
|
||||
_, err = auctionClient.AuctionSetOpenAuctionSlots(openAuctionSlotsConst)
|
||||
require.Nil(t, err)
|
||||
@@ -160,6 +167,7 @@ func TestAuctionSetClosedAuctionSlots(t *testing.T) {
|
||||
_, err := auctionClient.AuctionSetClosedAuctionSlots(newClosedAuctionSlots)
|
||||
require.Nil(t, err)
|
||||
closedAuctionSlots, err := auctionClient.AuctionGetClosedAuctionSlots()
|
||||
require.Nil(t, err)
|
||||
assert.Equal(t, newClosedAuctionSlots, closedAuctionSlots)
|
||||
_, err = auctionClient.AuctionSetClosedAuctionSlots(closedAuctionSlotsConst)
|
||||
require.Nil(t, err)
|
||||
@@ -180,6 +188,7 @@ func TestAuctionSetOutbidding(t *testing.T) {
|
||||
_, err := auctionClient.AuctionSetOutbidding(newOutbidding)
|
||||
require.Nil(t, err)
|
||||
outbidding, err := auctionClient.AuctionGetOutbidding()
|
||||
require.Nil(t, err)
|
||||
assert.Equal(t, newOutbidding, outbidding)
|
||||
_, err = auctionClient.AuctionSetOutbidding(outbiddingConst)
|
||||
require.Nil(t, err)
|
||||
@@ -200,6 +209,7 @@ func TestAuctionSetAllocationRatio(t *testing.T) {
|
||||
_, err := auctionClient.AuctionSetAllocationRatio(newAllocationRatio)
|
||||
require.Nil(t, err)
|
||||
allocationRatio, err := auctionClient.AuctionGetAllocationRatio()
|
||||
require.Nil(t, err)
|
||||
assert.Equal(t, newAllocationRatio, allocationRatio)
|
||||
_, err = auctionClient.AuctionSetAllocationRatio(allocationRatioConst)
|
||||
require.Nil(t, err)
|
||||
@@ -230,6 +240,7 @@ func TestAuctionSetDonationAddress(t *testing.T) {
|
||||
_, err := auctionClient.AuctionSetDonationAddress(newDonationAddress)
|
||||
require.Nil(t, err)
|
||||
donationAddress, err := auctionClient.AuctionGetDonationAddress()
|
||||
require.Nil(t, err)
|
||||
assert.Equal(t, &newDonationAddress, donationAddress)
|
||||
donationAddressConst := common.HexToAddress(donationAddressStr)
|
||||
_, err = auctionClient.AuctionSetDonationAddress(donationAddressConst)
|
||||
@@ -243,6 +254,7 @@ func TestAuctionSetBootCoordinator(t *testing.T) {
|
||||
_, err := auctionClient.AuctionSetBootCoordinator(newBootCoordinator)
|
||||
require.Nil(t, err)
|
||||
bootCoordinator, err := auctionClient.AuctionGetBootCoordinator()
|
||||
require.Nil(t, err)
|
||||
assert.Equal(t, &newBootCoordinator, bootCoordinator)
|
||||
bootCoordinatorConst := common.HexToAddress(bootCoordinatorStr)
|
||||
_, err = auctionClient.AuctionSetBootCoordinator(bootCoordinatorConst)
|
||||
|
||||
@@ -26,15 +26,15 @@ type RollupConstants struct {
|
||||
// Maxim Deposit allowed
|
||||
MaxAmountDeposit *big.Int
|
||||
MaxAmountL2 *big.Int
|
||||
MaxTokens *big.Int
|
||||
MaxTokens int64
|
||||
// maximum L1 transactions allowed to be queued for a batch
|
||||
MaxL1Tx *big.Int
|
||||
MaxL1Tx int
|
||||
// maximum L1 user transactions allowed to be queued for a batch
|
||||
MaxL1UserTx *big.Int
|
||||
MaxL1UserTx int
|
||||
Rfield *big.Int
|
||||
L1CoordinatorBytes *big.Int
|
||||
L1UserBytes *big.Int
|
||||
L2Bytes *big.Int
|
||||
L1CoordinatorBytes int
|
||||
L1UserBytes int
|
||||
L2Bytes int
|
||||
MaxTxVerifiers []int
|
||||
TokenHEZ ethCommon.Address
|
||||
// Only test
|
||||
@@ -48,9 +48,9 @@ type RollupConstants struct {
|
||||
ReservedIDx uint32
|
||||
LastIDx uint32
|
||||
ExitIDx uint32
|
||||
NoLimitToken *big.Int
|
||||
NumBuckets *big.Int
|
||||
MaxWDelay *big.Int
|
||||
NoLimitToken int
|
||||
NumBuckets int
|
||||
MaxWDelay int64
|
||||
}
|
||||
|
||||
// RollupVariables are the variables of the Rollup Smart Contract
|
||||
@@ -89,8 +89,8 @@ type RollupState struct {
|
||||
CurrentIdx int64
|
||||
}
|
||||
|
||||
// RollupEventL1UserTxEvent is an event of the Rollup Smart Contract
|
||||
type RollupEventL1UserTxEvent struct {
|
||||
// RollupEventL1UserTx is an event of the Rollup Smart Contract
|
||||
type RollupEventL1UserTx struct {
|
||||
L1Tx common.L1Tx
|
||||
QueueIndex *big.Int
|
||||
TransactionIndex *big.Int
|
||||
@@ -104,7 +104,7 @@ type RollupEventAddToken struct {
|
||||
|
||||
// RollupEventForgeBatch is an event of the Rollup Smart Contract
|
||||
type RollupEventForgeBatch struct {
|
||||
BatchNum *big.Int
|
||||
BatchNum int64
|
||||
EthTxHash ethCommon.Hash
|
||||
}
|
||||
|
||||
@@ -127,7 +127,7 @@ type RollupEventWithdrawEvent struct {
|
||||
|
||||
// RollupEvents is the list of events in a block of the Rollup Smart Contract
|
||||
type RollupEvents struct { //nolint:structcheck
|
||||
L1UserTxEvent []RollupEventL1UserTxEvent
|
||||
L1UserTx []RollupEventL1UserTx
|
||||
AddToken []RollupEventAddToken
|
||||
ForgeBatch []RollupEventForgeBatch
|
||||
UpdateForgeL1L2BatchTimeout []RollupEventUpdateForgeL1L2BatchTimeout
|
||||
@@ -138,7 +138,7 @@ type RollupEvents struct { //nolint:structcheck
|
||||
// NewRollupEvents creates an empty RollupEvents with the slices initialized.
|
||||
func NewRollupEvents() RollupEvents {
|
||||
return RollupEvents{
|
||||
L1UserTxEvent: make([]RollupEventL1UserTxEvent, 0),
|
||||
L1UserTx: make([]RollupEventL1UserTx, 0),
|
||||
AddToken: make([]RollupEventAddToken, 0),
|
||||
ForgeBatch: make([]RollupEventForgeBatch, 0),
|
||||
UpdateForgeL1L2BatchTimeout: make([]RollupEventUpdateForgeL1L2BatchTimeout, 0),
|
||||
@@ -332,24 +332,72 @@ func (c *RollupClient) RollupConstants() (*RollupConstants, error) {
|
||||
return err
|
||||
}
|
||||
// rollupConstants.GovernanceAddress :=
|
||||
rollupConstants.L1CoordinatorBytes, err = rollup.L1COORDINATORBYTES(nil)
|
||||
rollupConstants.L1UserBytes, err = rollup.L1USERBYTES(nil)
|
||||
rollupConstants.L2Bytes, err = rollup.L2BYTES(nil)
|
||||
l1CoordinatorBytes, err := rollup.L1COORDINATORBYTES(nil)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
rollupConstants.L1CoordinatorBytes = int(l1CoordinatorBytes.Int64())
|
||||
l1UserBytes, err := rollup.L1USERBYTES(nil)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
rollupConstants.L1UserBytes = int(l1UserBytes.Int64())
|
||||
l2Bytes, err := rollup.L2BYTES(nil)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
rollupConstants.L2Bytes = int(l2Bytes.Int64())
|
||||
rollupConstants.LastIDx, err = rollup.LASTIDX(nil)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
rollupConstants.MaxAmountDeposit, err = rollup.MAXLOADAMOUNT(nil)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
rollupConstants.MaxAmountL2, err = rollup.MAXAMOUNT(nil)
|
||||
rollupConstants.MaxL1Tx, err = rollup.MAXL1TX(nil)
|
||||
rollupConstants.MaxL1UserTx, err = rollup.MAXL1USERTX(nil)
|
||||
rollupConstants.MaxTokens, err = rollup.MAXTOKENS(nil)
|
||||
rollupConstants.MaxWDelay, err = rollup.MAXWITHDRAWALDELAY(nil)
|
||||
rollupConstants.NoLimitToken, err = rollup.NOLIMIT(nil)
|
||||
rollupConstants.NumBuckets, err = rollup.NUMBUCKETS(nil)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
maxL1Tx, err := rollup.MAXL1TX(nil)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
rollupConstants.MaxL1Tx = int(maxL1Tx.Int64())
|
||||
maxL1UserTx, err := rollup.MAXL1USERTX(nil)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
rollupConstants.MaxL1UserTx = int(maxL1UserTx.Int64())
|
||||
maxTokens, err := rollup.MAXTOKENS(nil)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
rollupConstants.MaxTokens = maxTokens.Int64()
|
||||
maxWDelay, err := rollup.MAXWITHDRAWALDELAY(nil)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
rollupConstants.MaxWDelay = maxWDelay.Int64()
|
||||
noLimitToken, err := rollup.NOLIMIT(nil)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
rollupConstants.NoLimitToken = int(noLimitToken.Int64())
|
||||
numBuckets, err := rollup.NUMBUCKETS(nil)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
rollupConstants.NumBuckets = int(numBuckets.Int64())
|
||||
// rollupConstants.ReservedIDx =
|
||||
rollupConstants.Rfield, err = rollup.RFIELD(nil)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
// rollupConstants.SafetyBot =
|
||||
// rollupConstants.TokenHEZ =
|
||||
// rollupConstants.WithdrawalContract =
|
||||
return err
|
||||
return nil
|
||||
}); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package eth
|
||||
|
||||
import (
|
||||
"io/ioutil"
|
||||
"testing"
|
||||
|
||||
"github.com/ethereum/go-ethereum/accounts/keystore"
|
||||
@@ -14,9 +15,13 @@ var rollupClient *RollupClient
|
||||
func TestNewRollupClient(t *testing.T) {
|
||||
key, err := crypto.HexToECDSA(governancePrivateKey)
|
||||
require.Nil(t, err)
|
||||
ks := keystore.NewKeyStore(pathKs, keystore.StandardScryptN, keystore.StandardScryptP)
|
||||
dir, err := ioutil.TempDir("", "tmpks")
|
||||
require.Nil(t, err)
|
||||
ks := keystore.NewKeyStore(dir, keystore.StandardScryptN, keystore.StandardScryptP)
|
||||
account, err := ks.ImportECDSA(key, password)
|
||||
ks.Unlock(account, password)
|
||||
require.Nil(t, err)
|
||||
err = ks.Unlock(account, password)
|
||||
require.Nil(t, err)
|
||||
// Init eth client
|
||||
ethClient, err := ethclient.Dial(ehtClientDialURL)
|
||||
require.Nil(t, err)
|
||||
|
||||
@@ -231,20 +231,18 @@ func NewClientSetupExample() *ClientSetup {
|
||||
L1CoordinatorBytes: 101,
|
||||
L1UserBytes: 68,
|
||||
L2Bytes: 11,
|
||||
}
|
||||
rollupVariables := ð.RollupVariables{
|
||||
MaxTxVerifiers: []int{512, 1024, 2048},
|
||||
TokenHEZ: tokenHEZ,
|
||||
GovernanceAddress: governanceAddress,
|
||||
SafetyBot: ethCommon.HexToAddress("0x84d8B79E84fe87B14ad61A554e740f6736bF4c20"),
|
||||
ConsensusContract: ethCommon.HexToAddress("0x8E442975805fb1908f43050c9C1A522cB0e28D7b"),
|
||||
WithdrawalContract: ethCommon.HexToAddress("0x5CB7979cBdbf65719BEE92e4D15b7b7Ed3D79114"),
|
||||
FeeAddToken: big.NewInt(11),
|
||||
ForgeL1Timeout: 9,
|
||||
FeeL1UserTx: big.NewInt(22),
|
||||
}
|
||||
rollupVariables := ð.RollupVariables{
|
||||
FeeAddToken: big.NewInt(11),
|
||||
ForgeL1Timeout: 9,
|
||||
}
|
||||
auctionConstants := ð.AuctionConstants{
|
||||
DelayGenesis: 0,
|
||||
BlocksPerSlot: 40,
|
||||
InitialMinimalBidding: initialMinimalBidding,
|
||||
GenesisBlockNum: 0,
|
||||
@@ -633,8 +631,8 @@ func (c *Client) RollupAddToken(tokenAddress ethCommon.Address) (tx *types.Trans
|
||||
// return nil, errTODO
|
||||
// }
|
||||
|
||||
// RollupWithdrawMerkleProof is the interface to call the smart contract function
|
||||
func (c *Client) RollupWithdrawMerkleProof(tokenID int64, balance *big.Int, babyPubKey *babyjub.PublicKey, numExitRoot int64, siblings []*big.Int, idx int64, instantWithdraw bool) (tx *types.Transaction, err error) {
|
||||
// RollupWithdraw is the interface to call the smart contract function
|
||||
func (c *Client) RollupWithdraw(tokenID int64, balance *big.Int, babyPubKey *babyjub.PublicKey, numExitRoot int64, siblings []*big.Int, idx int64, instantWithdraw bool) (tx *types.Transaction, err error) {
|
||||
c.rw.Lock()
|
||||
defer c.rw.Unlock()
|
||||
cpy := c.nextBlock().copy()
|
||||
@@ -677,6 +675,15 @@ func (c *Client) RollupCreateAccountDepositTransfer(babyPubKey babyjub.PublicKey
|
||||
return nil, errTODO
|
||||
}
|
||||
|
||||
// RollupGetCurrentTokens is the interface to call the smart contract function
|
||||
func (c *Client) RollupGetCurrentTokens() (*big.Int, error) {
|
||||
c.rw.RLock()
|
||||
defer c.rw.RUnlock()
|
||||
|
||||
log.Error("TODO")
|
||||
return nil, errTODO
|
||||
}
|
||||
|
||||
// RollupDepositTransfer is the interface to call the smart contract function
|
||||
func (c *Client) RollupDepositTransfer(fromIdx int64, loadAmountF, amountF utils.Float16, tokenID int64, toIdx int64) (tx *types.Transaction, err error) {
|
||||
c.rw.Lock()
|
||||
@@ -722,45 +729,34 @@ func (c *Client) RollupCreateAccountDeposit(babyPubKey babyjub.PublicKey, loadAm
|
||||
}
|
||||
|
||||
// RollupGetTokenAddress is the interface to call the smart contract function
|
||||
func (c *Client) RollupGetTokenAddress(tokenID int64) (*ethCommon.Address, error) {
|
||||
c.rw.RLock()
|
||||
defer c.rw.RUnlock()
|
||||
|
||||
log.Error("TODO")
|
||||
return nil, errTODO
|
||||
}
|
||||
// func (c *Client) RollupGetTokenAddress(tokenID int64) (*ethCommon.Address, error) {
|
||||
// c.rw.RLock()
|
||||
// defer c.rw.RUnlock()
|
||||
//
|
||||
// log.Error("TODO")
|
||||
// return nil, errTODO
|
||||
// }
|
||||
|
||||
// RollupGetL1TxFromQueue is the interface to call the smart contract function
|
||||
func (c *Client) RollupGetL1TxFromQueue(queue int64, position int64) ([]byte, error) {
|
||||
c.rw.RLock()
|
||||
defer c.rw.RUnlock()
|
||||
|
||||
log.Error("TODO")
|
||||
return nil, errTODO
|
||||
}
|
||||
// func (c *Client) RollupGetL1TxFromQueue(queue int64, position int64) ([]byte, error) {
|
||||
// c.rw.RLock()
|
||||
// defer c.rw.RUnlock()
|
||||
//
|
||||
// log.Error("TODO")
|
||||
// return nil, errTODO
|
||||
// }
|
||||
|
||||
// RollupGetQueue is the interface to call the smart contract function
|
||||
func (c *Client) RollupGetQueue(queue int64) ([]byte, error) {
|
||||
c.rw.RLock()
|
||||
defer c.rw.RUnlock()
|
||||
// func (c *Client) RollupGetQueue(queue int64) ([]byte, error) {
|
||||
// c.rw.RLock()
|
||||
// defer c.rw.RUnlock()
|
||||
//
|
||||
// log.Error("TODO")
|
||||
// return nil, errTODO
|
||||
// }
|
||||
|
||||
log.Error("TODO")
|
||||
return nil, errTODO
|
||||
}
|
||||
|
||||
// RollupUpdateForgeL1Timeout is the interface to call the smart contract function
|
||||
func (c *Client) RollupUpdateForgeL1Timeout(newForgeL1Timeout int64) (tx *types.Transaction, err error) {
|
||||
c.rw.Lock()
|
||||
defer c.rw.Unlock()
|
||||
cpy := c.nextBlock().copy()
|
||||
defer func() { c.revertIfErr(err, cpy) }()
|
||||
|
||||
log.Error("TODO")
|
||||
return nil, errTODO
|
||||
}
|
||||
|
||||
// RollupUpdateFeeL1UserTx is the interface to call the smart contract function
|
||||
func (c *Client) RollupUpdateFeeL1UserTx(newFeeL1UserTx *big.Int) (tx *types.Transaction, err error) {
|
||||
// RollupUpdateForgeL1L2BatchTimeout is the interface to call the smart contract function
|
||||
func (c *Client) RollupUpdateForgeL1L2BatchTimeout(newForgeL1Timeout int64) (tx *types.Transaction, err error) {
|
||||
c.rw.Lock()
|
||||
defer c.rw.Unlock()
|
||||
cpy := c.nextBlock().copy()
|
||||
@@ -782,15 +778,15 @@ func (c *Client) RollupUpdateFeeAddToken(newFeeAddToken *big.Int) (tx *types.Tra
|
||||
}
|
||||
|
||||
// RollupUpdateTokensHEZ is the interface to call the smart contract function
|
||||
func (c *Client) RollupUpdateTokensHEZ(newTokenHEZ ethCommon.Address) (tx *types.Transaction, err error) {
|
||||
c.rw.Lock()
|
||||
defer c.rw.Unlock()
|
||||
cpy := c.nextBlock().copy()
|
||||
defer func() { c.revertIfErr(err, cpy) }()
|
||||
|
||||
log.Error("TODO")
|
||||
return nil, errTODO
|
||||
}
|
||||
// func (c *Client) RollupUpdateTokensHEZ(newTokenHEZ ethCommon.Address) (tx *types.Transaction, err error) {
|
||||
// c.rw.Lock()
|
||||
// defer c.rw.Unlock()
|
||||
// cpy := c.nextBlock().copy()
|
||||
// defer func() { c.revertIfErr(err, cpy) }()
|
||||
//
|
||||
// log.Error("TODO")
|
||||
// return nil, errTODO
|
||||
// }
|
||||
|
||||
// RollupUpdateGovernance is the interface to call the smart contract function
|
||||
// func (c *Client) RollupUpdateGovernance() (*types.Transaction, error) { // TODO (Not defined in Hermez.sol)
|
||||
@@ -1132,13 +1128,13 @@ func (c *Client) AuctionMultiBid(startingSlot int64, endingSlot int64, slotSet [
|
||||
}
|
||||
|
||||
// AuctionCanForge is the interface to call the smart contract function
|
||||
func (c *Client) AuctionCanForge(forger ethCommon.Address) (bool, error) {
|
||||
func (c *Client) AuctionCanForge(forger ethCommon.Address, blockNum int64) (bool, error) {
|
||||
c.rw.RLock()
|
||||
defer c.rw.RUnlock()
|
||||
|
||||
currentBlock := c.currentBlock()
|
||||
a := currentBlock.Auction
|
||||
return a.canForge(forger, a.Eth.BlockNum)
|
||||
return a.canForge(forger, blockNum)
|
||||
}
|
||||
|
||||
// AuctionForge is the interface to call the smart contract function
|
||||
@@ -1147,7 +1143,7 @@ func (c *Client) AuctionCanForge(forger ethCommon.Address) (bool, error) {
|
||||
// }
|
||||
|
||||
// AuctionClaimHEZ is the interface to call the smart contract function
|
||||
func (c *Client) AuctionClaimHEZ() (tx *types.Transaction, err error) {
|
||||
func (c *Client) AuctionClaimHEZ(claimAddress ethCommon.Address) (tx *types.Transaction, err error) {
|
||||
c.rw.Lock()
|
||||
defer c.rw.Unlock()
|
||||
cpy := c.nextBlock().copy()
|
||||
|
||||
Reference in New Issue
Block a user