Update importers of eth, review eth/README.md

This commit is contained in:
Eduard S
2020-10-26 16:01:38 +01:00
parent 2e67008142
commit 79b105b497
17 changed files with 157 additions and 126 deletions

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)