diff --git a/eth/auction.go b/eth/auction.go index 4a9852b..668aabc 100644 --- a/eth/auction.go +++ b/eth/auction.go @@ -243,8 +243,8 @@ type AuctionInterface interface { // Bidding // AuctionTokensReceived(operator, from, to ethCommon.Address, amount *big.Int, // userData, operatorData []byte) error // Only called from another smart contract - AuctionBid(slot int64, bidAmount *big.Int, forger, tokenAddress 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) + 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 ethCommon.Address) (*types.Transaction, error) // Forge AuctionCanForge(forger ethCommon.Address, blockNum int64) (bool, error) @@ -267,17 +267,19 @@ 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 - gasLimit uint64 + client *EthereumClient + address ethCommon.Address + tokenAddress ethCommon.Address + gasLimit uint64 } -// NewAuctionClient creates a new AuctionClient -func NewAuctionClient(client *EthereumClient, address ethCommon.Address) *AuctionClient { +// NewAuctionClient creates a new AuctionClient. `tokenAddress` is the address of the HEZ tokens. +func NewAuctionClient(client *EthereumClient, address, tokenAddress ethCommon.Address) *AuctionClient { return &AuctionClient{ - client: client, - address: address, - gasLimit: 1000000, //nolint:gomnd + client: client, + address: address, + tokenAddress: tokenAddress, + 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 -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 err error if tx, err = c.client.CallAuth( c.gasLimit, 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 { 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 -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 err error if tx, err = c.client.CallAuth( c.gasLimit, 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 { return nil, err } diff --git a/eth/auction_test.go b/eth/auction_test.go index a9f618b..6670a53 100644 --- a/eth/auction_test.go +++ b/eth/auction_test.go @@ -68,8 +68,9 @@ func TestNewAction(t *testing.T) { require.Nil(t, err) ethereumClient := NewEthereumClient(ethClient, &account, ks, nil) auctionAddress := common.HexToAddress(auctionAddressStr) + tokenAddress := common.HexToAddress(tokenHezStr) 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.SetString("11000000000000000000", 10) forgerAddress := common.HexToAddress(governanceAddressStr) - _, err = auctionClient.AuctionBid(currentSlot+4, bidAmount, forgerAddress, TOKENHEZ) + _, err = auctionClient.AuctionBid(currentSlot+4, bidAmount, forgerAddress) require.Nil(t, err) } } @@ -368,7 +369,7 @@ func TestAuctionMultiBid(t *testing.T) { budget := new(big.Int) budget.SetString("110000000000000000000", 10) 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) } } diff --git a/go.mod b/go.mod index 8e34fbc..e805ad1 100644 --- a/go.mod +++ b/go.mod @@ -22,5 +22,6 @@ require ( github.com/urfave/cli/v2 v2.2.0 go.uber.org/multierr v1.6.0 // indirect 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 ) diff --git a/test/ethclient.go b/test/ethclient.go index d43620a..764b252 100644 --- a/test/ethclient.go +++ b/test/ethclient.go @@ -1068,7 +1068,7 @@ func (c *Client) AuctionGetDefaultSlotSetBid(slotSet uint8) (*big.Int, error) { // } // 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() defer c.rw.Unlock() 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 -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() defer c.rw.Unlock() cpy := c.nextBlock().copy() diff --git a/test/ethclient_test.go b/test/ethclient_test.go index 621b380..afe3ce0 100644 --- a/test/ethclient_test.go +++ b/test/ethclient_test.go @@ -68,7 +68,6 @@ func TestClientAuction(t *testing.T) { addrWithdraw := ethCommon.HexToAddress("0x6b175474e89094c44da98b954eedeac495271d0f") addrForge := ethCommon.HexToAddress("0xCfAA413eEb796f328620a3630Ae39124cabcEa92") addrForge2 := ethCommon.HexToAddress("0x1fCb4ac309428feCc61B1C8cA5823C15A5e1a800") - token1Addr := ethCommon.HexToAddress("0x6b175474e89094c44da98b954eedeac495271d0f") var timer timer 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. - _, err := c.AuctionBid(0, big.NewInt(1), addrForge, token1Addr) + _, err := c.AuctionBid(0, big.NewInt(1), addrForge) 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) // 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) _, err = c.AuctionRegisterCoordinator(addrForge, "https://foo.bar") 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) - _, err = c.AuctionBid(3, big.NewInt(1650), addrForge, token1Addr) + _, err = c.AuctionBid(3, big.NewInt(1650), addrForge) assert.Nil(t, err) _, err = c.AuctionRegisterCoordinator(addrForge2, "https://foo2.bar") 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) // 1650 + 10% = 1815 - _, err = c.AuctionBid(3, big.NewInt(1815), addrForge2, token1Addr) + _, err = c.AuctionBid(3, big.NewInt(1815), addrForge2) assert.Nil(t, err) c.CtlMineBlock()