Skip to content

Commit

Permalink
Include contract address in signature
Browse files Browse the repository at this point in the history
  • Loading branch information
lpopo0856 committed Nov 8, 2023
1 parent 22555c5 commit 9040dff
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 8 deletions.
9 changes: 8 additions & 1 deletion contracts/FeralfileEnglishAuction.sol
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,14 @@ contract FeralfileEnglishAuction is Ownable, IFeralfileSaleData, ECDSASigner {
"FeralfileEnglishAuction: signature is expired"
);
bytes32 message_ = keccak256(
abi.encode(block.chainid, auctionID_, bidder_, amount_, expiryTime_)
abi.encode(
block.chainid,
address(this),
auctionID_,
bidder_,
amount_,
expiryTime_
)
);
require(
isValidSignature(message_, r_, s_, v_),
Expand Down
20 changes: 13 additions & 7 deletions test/feralfile_english_auction.js
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ contract("FeralfileEnglishAuction", async (accounts) => {
it("test bid on auction by Feralfile successfully", async function () {
const auctionID = "3";
const nowTime = await time.latest();
const startTime = nowTime.add(new BN(1)).toString(); // start in 1 second
const startTime = nowTime.toString(); // start now
const endTime = nowTime.add(new BN(10)).toString(); // end in 10 seconds

await this.engAuction.registerAuctions([
Expand All @@ -265,9 +265,10 @@ contract("FeralfileEnglishAuction", async (accounts) => {

// Generate signature
const signParams = web3.eth.abi.encodeParameters(
["uint", "uint256", "address", "uint256", "uint256"],
["uint", "address", "uint256", "address", "uint256", "uint256"],
[
BigInt(await web3.eth.getChainId()).toString(),
this.engAuction.address,
auctionID,
accounts[2],
web3.utils.toWei("0.25", "ether"),
Expand Down Expand Up @@ -454,9 +455,10 @@ contract("FeralfileEnglishAuction", async (accounts) => {
const biddingExpiry = nowTime.add(new BN(600)).toString();
// Generate signature
const biddingParams = web3.eth.abi.encodeParameters(
["uint", "uint256", "address", "uint256", "uint256"],
["uint", "address", "uint256", "address", "uint256", "uint256"],
[
BigInt(await web3.eth.getChainId()).toString(),
this.engAuction.address,
auctionID,
accounts[3],
web3.utils.toWei("0.3", "ether"),
Expand Down Expand Up @@ -528,9 +530,10 @@ contract("FeralfileEnglishAuction", async (accounts) => {
const biddingExpiry = nowTime.add(new BN(600)).toString();
// Generate signature
const biddingParams = web3.eth.abi.encodeParameters(
["uint", "uint256", "address", "uint256", "uint256"],
["uint", "address", "uint256", "address", "uint256", "uint256"],
[
BigInt(await web3.eth.getChainId()).toString(),
this.engAuction.address,
auctionID,
accounts[2],
web3.utils.toWei("0.2", "ether"),
Expand Down Expand Up @@ -608,9 +611,10 @@ contract("FeralfileEnglishAuction", async (accounts) => {
const biddingExpiry2 = nowTime.add(new BN(600)).toString();
// Generate signature
const biddingParams2 = web3.eth.abi.encodeParameters(
["uint", "uint256", "address", "uint256", "uint256"],
["uint", "address", "uint256", "address", "uint256", "uint256"],
[
BigInt(await web3.eth.getChainId()).toString(),
this.engAuction.address,
auctionID,
accounts[2],
web3.utils.toWei("0.2", "ether"),
Expand Down Expand Up @@ -650,9 +654,10 @@ contract("FeralfileEnglishAuction", async (accounts) => {
const biddingExpiry3 = (await time.latest()).add(new BN(600)).toString();
// Generate signature
const biddingParams = web3.eth.abi.encodeParameters(
["uint", "uint256", "address", "uint256", "uint256"],
["uint", "address", "uint256", "address", "uint256", "uint256"],
[
BigInt(await web3.eth.getChainId()).toString(),
this.engAuction.address,
auctionID,
accounts[3],
web3.utils.toWei("0.3", "ether"),
Expand Down Expand Up @@ -819,9 +824,10 @@ contract("FeralfileEnglishAuction", async (accounts) => {
const biddingExpiry = nowTime.add(new BN(600)).toString();
// Generate signature
const biddingParams = web3.eth.abi.encodeParameters(
["uint", "uint256", "address", "uint256", "uint256"],
["uint", "address", "uint256", "address", "uint256", "uint256"],
[
BigInt(await web3.eth.getChainId()).toString(),
this.engAuction.address,
this.auctionID2,
accounts[3],
web3.utils.toWei("0.25", "ether"),
Expand Down

0 comments on commit 9040dff

Please sign in to comment.