mirror of
https://github.com/arnaucube/hermez-node.git
synced 2026-02-07 11:26:44 +01:00
Pass tokenAddress to AuctionClient constructor
This commit is contained in:
@@ -243,8 +243,8 @@ type AuctionInterface interface {
|
|||||||
// Bidding
|
// Bidding
|
||||||
// AuctionTokensReceived(operator, from, to ethCommon.Address, amount *big.Int,
|
// AuctionTokensReceived(operator, from, to ethCommon.Address, amount *big.Int,
|
||||||
// userData, operatorData []byte) error // Only called from another smart contract
|
// userData, operatorData []byte) error // Only called from another smart contract
|
||||||
AuctionBid(slot int64, bidAmount *big.Int, forger, tokenAddress ethCommon.Address) (*types.Transaction, error)
|
AuctionBid(slot int64, bidAmount *big.Int, forger ethCommon.Address) (*types.Transaction, error)
|
||||||
AuctionMultiBid(startingSlot int64, endingSlot int64, slotSet [6]bool, maxBid, closedMinBid, budget *big.Int, forger, tokenAddress ethCommon.Address) (*types.Transaction, error)
|
AuctionMultiBid(startingSlot int64, endingSlot int64, slotSet [6]bool, maxBid, closedMinBid, budget *big.Int, forger ethCommon.Address) (*types.Transaction, error)
|
||||||
|
|
||||||
// Forge
|
// Forge
|
||||||
AuctionCanForge(forger ethCommon.Address, blockNum int64) (bool, error)
|
AuctionCanForge(forger ethCommon.Address, blockNum int64) (bool, error)
|
||||||
@@ -269,14 +269,16 @@ type AuctionInterface interface {
|
|||||||
type AuctionClient struct {
|
type AuctionClient struct {
|
||||||
client *EthereumClient
|
client *EthereumClient
|
||||||
address ethCommon.Address
|
address ethCommon.Address
|
||||||
|
tokenAddress ethCommon.Address
|
||||||
gasLimit uint64
|
gasLimit uint64
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewAuctionClient creates a new AuctionClient
|
// NewAuctionClient creates a new AuctionClient. `tokenAddress` is the address of the HEZ tokens.
|
||||||
func NewAuctionClient(client *EthereumClient, address ethCommon.Address) *AuctionClient {
|
func NewAuctionClient(client *EthereumClient, address, tokenAddress ethCommon.Address) *AuctionClient {
|
||||||
return &AuctionClient{
|
return &AuctionClient{
|
||||||
client: client,
|
client: client,
|
||||||
address: address,
|
address: address,
|
||||||
|
tokenAddress: tokenAddress,
|
||||||
gasLimit: 1000000, //nolint:gomnd
|
gasLimit: 1000000, //nolint:gomnd
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -689,13 +691,13 @@ func (c *AuctionClient) AuctionGetDefaultSlotSetBid(slotSet uint8) (*big.Int, er
|
|||||||
// }
|
// }
|
||||||
|
|
||||||
// AuctionBid is the interface to call the smart contract function
|
// AuctionBid is the interface to call the smart contract function
|
||||||
func (c *AuctionClient) AuctionBid(slot int64, bidAmount *big.Int, forger, tokenAddress ethCommon.Address) (*types.Transaction, error) {
|
func (c *AuctionClient) AuctionBid(slot int64, bidAmount *big.Int, forger ethCommon.Address) (*types.Transaction, error) {
|
||||||
var tx *types.Transaction
|
var tx *types.Transaction
|
||||||
var err error
|
var err error
|
||||||
if tx, err = c.client.CallAuth(
|
if tx, err = c.client.CallAuth(
|
||||||
c.gasLimit,
|
c.gasLimit,
|
||||||
func(ec *ethclient.Client, auth *bind.TransactOpts) (*types.Transaction, error) {
|
func(ec *ethclient.Client, auth *bind.TransactOpts) (*types.Transaction, error) {
|
||||||
tokens, err := ERC777.NewERC777(tokenAddress, ec)
|
tokens, err := ERC777.NewERC777(c.tokenAddress, ec)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@@ -725,13 +727,13 @@ func (c *AuctionClient) AuctionBid(slot int64, bidAmount *big.Int, forger, token
|
|||||||
}
|
}
|
||||||
|
|
||||||
// AuctionMultiBid is the interface to call the smart contract function
|
// 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, forger, tokenAddress ethCommon.Address) (*types.Transaction, error) {
|
func (c *AuctionClient) AuctionMultiBid(startingSlot int64, endingSlot int64, slotSet [6]bool, maxBid, closedMinBid, budget *big.Int, forger ethCommon.Address) (*types.Transaction, error) {
|
||||||
var tx *types.Transaction
|
var tx *types.Transaction
|
||||||
var err error
|
var err error
|
||||||
if tx, err = c.client.CallAuth(
|
if tx, err = c.client.CallAuth(
|
||||||
c.gasLimit,
|
c.gasLimit,
|
||||||
func(ec *ethclient.Client, auth *bind.TransactOpts) (*types.Transaction, error) {
|
func(ec *ethclient.Client, auth *bind.TransactOpts) (*types.Transaction, error) {
|
||||||
tokens, err := ERC777.NewERC777(tokenAddress, ec)
|
tokens, err := ERC777.NewERC777(c.tokenAddress, ec)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -68,8 +68,9 @@ func TestNewAction(t *testing.T) {
|
|||||||
require.Nil(t, err)
|
require.Nil(t, err)
|
||||||
ethereumClient := NewEthereumClient(ethClient, &account, ks, nil)
|
ethereumClient := NewEthereumClient(ethClient, &account, ks, nil)
|
||||||
auctionAddress := common.HexToAddress(auctionAddressStr)
|
auctionAddress := common.HexToAddress(auctionAddressStr)
|
||||||
|
tokenAddress := common.HexToAddress(tokenHezStr)
|
||||||
if integration != "" {
|
if integration != "" {
|
||||||
auctionClient = NewAuctionClient(ethereumClient, auctionAddress)
|
auctionClient = NewAuctionClient(ethereumClient, auctionAddress, tokenAddress)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -351,7 +352,7 @@ func TestAuctionBid(t *testing.T) {
|
|||||||
bidAmount := new(big.Int)
|
bidAmount := new(big.Int)
|
||||||
bidAmount.SetString("11000000000000000000", 10)
|
bidAmount.SetString("11000000000000000000", 10)
|
||||||
forgerAddress := common.HexToAddress(governanceAddressStr)
|
forgerAddress := common.HexToAddress(governanceAddressStr)
|
||||||
_, err = auctionClient.AuctionBid(currentSlot+4, bidAmount, forgerAddress, TOKENHEZ)
|
_, err = auctionClient.AuctionBid(currentSlot+4, bidAmount, forgerAddress)
|
||||||
require.Nil(t, err)
|
require.Nil(t, err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -368,7 +369,7 @@ func TestAuctionMultiBid(t *testing.T) {
|
|||||||
budget := new(big.Int)
|
budget := new(big.Int)
|
||||||
budget.SetString("110000000000000000000", 10)
|
budget.SetString("110000000000000000000", 10)
|
||||||
forgerAddress := common.HexToAddress(governanceAddressStr)
|
forgerAddress := common.HexToAddress(governanceAddressStr)
|
||||||
_, err = auctionClient.AuctionMultiBid(currentSlot+5, currentSlot+10, slotSet, maxBid, minBid, budget, forgerAddress, TOKENHEZ)
|
_, err = auctionClient.AuctionMultiBid(currentSlot+5, currentSlot+10, slotSet, maxBid, minBid, budget, forgerAddress)
|
||||||
require.Nil(t, err)
|
require.Nil(t, err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
1
go.mod
1
go.mod
@@ -22,5 +22,6 @@ require (
|
|||||||
github.com/urfave/cli/v2 v2.2.0
|
github.com/urfave/cli/v2 v2.2.0
|
||||||
go.uber.org/multierr v1.6.0 // indirect
|
go.uber.org/multierr v1.6.0 // indirect
|
||||||
go.uber.org/zap v1.16.0
|
go.uber.org/zap v1.16.0
|
||||||
|
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9
|
||||||
gopkg.in/go-playground/validator.v9 v9.29.1
|
gopkg.in/go-playground/validator.v9 v9.29.1
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -1068,7 +1068,7 @@ func (c *Client) AuctionGetDefaultSlotSetBid(slotSet uint8) (*big.Int, error) {
|
|||||||
// }
|
// }
|
||||||
|
|
||||||
// AuctionBid is the interface to call the smart contract function
|
// AuctionBid is the interface to call the smart contract function
|
||||||
func (c *Client) AuctionBid(slot int64, bidAmount *big.Int, forger, tokenAddress ethCommon.Address) (tx *types.Transaction, err error) {
|
func (c *Client) AuctionBid(slot int64, bidAmount *big.Int, forger ethCommon.Address) (tx *types.Transaction, err error) {
|
||||||
c.rw.Lock()
|
c.rw.Lock()
|
||||||
defer c.rw.Unlock()
|
defer c.rw.Unlock()
|
||||||
cpy := c.nextBlock().copy()
|
cpy := c.nextBlock().copy()
|
||||||
@@ -1117,7 +1117,7 @@ func (c *Client) AuctionBid(slot int64, bidAmount *big.Int, forger, tokenAddress
|
|||||||
}
|
}
|
||||||
|
|
||||||
// AuctionMultiBid is the interface to call the smart contract function
|
// 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, forger, tokenAddress ethCommon.Address) (tx *types.Transaction, err error) {
|
func (c *Client) AuctionMultiBid(startingSlot int64, endingSlot int64, slotSet [6]bool, maxBid, closedMinBid, budget *big.Int, forger ethCommon.Address) (tx *types.Transaction, err error) {
|
||||||
c.rw.Lock()
|
c.rw.Lock()
|
||||||
defer c.rw.Unlock()
|
defer c.rw.Unlock()
|
||||||
cpy := c.nextBlock().copy()
|
cpy := c.nextBlock().copy()
|
||||||
|
|||||||
@@ -68,7 +68,6 @@ func TestClientAuction(t *testing.T) {
|
|||||||
addrWithdraw := ethCommon.HexToAddress("0x6b175474e89094c44da98b954eedeac495271d0f")
|
addrWithdraw := ethCommon.HexToAddress("0x6b175474e89094c44da98b954eedeac495271d0f")
|
||||||
addrForge := ethCommon.HexToAddress("0xCfAA413eEb796f328620a3630Ae39124cabcEa92")
|
addrForge := ethCommon.HexToAddress("0xCfAA413eEb796f328620a3630Ae39124cabcEa92")
|
||||||
addrForge2 := ethCommon.HexToAddress("0x1fCb4ac309428feCc61B1C8cA5823C15A5e1a800")
|
addrForge2 := ethCommon.HexToAddress("0x1fCb4ac309428feCc61B1C8cA5823C15A5e1a800")
|
||||||
token1Addr := ethCommon.HexToAddress("0x6b175474e89094c44da98b954eedeac495271d0f")
|
|
||||||
|
|
||||||
var timer timer
|
var timer timer
|
||||||
clientSetup := NewClientSetupExample()
|
clientSetup := NewClientSetupExample()
|
||||||
@@ -81,33 +80,33 @@ func TestClientAuction(t *testing.T) {
|
|||||||
|
|
||||||
// Check several cases in which bid doesn't succed, and also do 2 successful bids.
|
// Check several cases in which bid doesn't succed, and also do 2 successful bids.
|
||||||
|
|
||||||
_, err := c.AuctionBid(0, big.NewInt(1), addrForge, token1Addr)
|
_, err := c.AuctionBid(0, big.NewInt(1), addrForge)
|
||||||
assert.Equal(t, errBidClosed, err)
|
assert.Equal(t, errBidClosed, err)
|
||||||
|
|
||||||
_, err = c.AuctionBid(4322, big.NewInt(1), addrForge, token1Addr)
|
_, err = c.AuctionBid(4322, big.NewInt(1), addrForge)
|
||||||
assert.Equal(t, errBidNotOpen, err)
|
assert.Equal(t, errBidNotOpen, err)
|
||||||
|
|
||||||
// 101 % 6 = 5; defaultSlotSetBid[5] = 1500; 1500 + 10% = 1650
|
// 101 % 6 = 5; defaultSlotSetBid[5] = 1500; 1500 + 10% = 1650
|
||||||
_, err = c.AuctionBid(101, big.NewInt(1650), addrForge, token1Addr)
|
_, err = c.AuctionBid(101, big.NewInt(1650), addrForge)
|
||||||
assert.Equal(t, errCoordNotReg, err)
|
assert.Equal(t, errCoordNotReg, err)
|
||||||
|
|
||||||
_, err = c.AuctionRegisterCoordinator(addrForge, "https://foo.bar")
|
_, err = c.AuctionRegisterCoordinator(addrForge, "https://foo.bar")
|
||||||
assert.Nil(t, err)
|
assert.Nil(t, err)
|
||||||
|
|
||||||
_, err = c.AuctionBid(3, big.NewInt(1), addrForge, token1Addr)
|
_, err = c.AuctionBid(3, big.NewInt(1), addrForge)
|
||||||
assert.Equal(t, errBidBelowMin, err)
|
assert.Equal(t, errBidBelowMin, err)
|
||||||
|
|
||||||
_, err = c.AuctionBid(3, big.NewInt(1650), addrForge, token1Addr)
|
_, err = c.AuctionBid(3, big.NewInt(1650), addrForge)
|
||||||
assert.Nil(t, err)
|
assert.Nil(t, err)
|
||||||
|
|
||||||
_, err = c.AuctionRegisterCoordinator(addrForge2, "https://foo2.bar")
|
_, err = c.AuctionRegisterCoordinator(addrForge2, "https://foo2.bar")
|
||||||
assert.Nil(t, err)
|
assert.Nil(t, err)
|
||||||
|
|
||||||
_, err = c.AuctionBid(3, big.NewInt(16), addrForge2, token1Addr)
|
_, err = c.AuctionBid(3, big.NewInt(16), addrForge2)
|
||||||
assert.Equal(t, errBidBelowMin, err)
|
assert.Equal(t, errBidBelowMin, err)
|
||||||
|
|
||||||
// 1650 + 10% = 1815
|
// 1650 + 10% = 1815
|
||||||
_, err = c.AuctionBid(3, big.NewInt(1815), addrForge2, token1Addr)
|
_, err = c.AuctionBid(3, big.NewInt(1815), addrForge2)
|
||||||
assert.Nil(t, err)
|
assert.Nil(t, err)
|
||||||
|
|
||||||
c.CtlMineBlock()
|
c.CtlMineBlock()
|
||||||
|
|||||||
Reference in New Issue
Block a user