Skip to content

Commit

Permalink
Add check&test for total bps over 10k
Browse files Browse the repository at this point in the history
  • Loading branch information
lpopo0856 committed Jul 17, 2023
1 parent bd4be38 commit a140159
Show file tree
Hide file tree
Showing 2 changed files with 118 additions and 1 deletion.
6 changes: 6 additions & 0 deletions contracts/FeralfileArtworkV4.sol
Original file line number Diff line number Diff line change
Expand Up @@ -461,6 +461,12 @@ contract FeralfileExhibitionV4 is
emit BuyArtwork(saleData_.destination, saleData_.tokenIds[i]);
}

require(
saleData_.price >= distributedRevenue &&
saleData_.price - distributedRevenue >= saleData_.cost,
"FeralfileExhibitionV4: total bps over 10,000"
);

// Transfer cost, platform revenue and remaining funds
uint256 leftOver = saleData_.price - distributedRevenue;
if (leftOver > 0) {
Expand Down
113 changes: 112 additions & 1 deletion test/feralfile_exhibition_v4.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ contract("FeralfileExhibitionV4_0", async (accounts) => {

// Deploy multiple contracts
this.contracts = [];
for (let i = 0; i < 7; i++) {
for (let i = 0; i < 8; i++) {
let contract = await FeralfileExhibitionV4.new(
"Feral File V4 Test",
"FFv4",
Expand Down Expand Up @@ -583,6 +583,117 @@ contract("FeralfileExhibitionV4_0", async (accounts) => {
}
});

it("test buy artworks failed with total bps over 10k", async function () {
let contract = this.contracts[7];

// Mint for buy by crypto
let owner = contract.address;
await contract.mintArtworks([
[this.seriesIds[3], 3000000, owner],
[this.seriesIds[3], 3000001, owner],
[this.seriesIds[4], 4000000, owner],
[this.seriesIds[4], 4000001, owner],
[this.seriesIds[4], 4000002, owner],
]);

// Generate signature
const expiryTime = (new Date().getTime() / 1000 + 300).toFixed(0);
const signParams = web3.eth.abi.encodeParameters(
[
"uint",
"address",
"tuple(uint256,uint256,uint256,address,uint256[],tuple(address,uint256)[][],bool)",
],
[
BigInt(await web3.eth.getChainId()).toString(),
contract.address,
[
BigInt(0.25 * 1e18).toString(),
BigInt(0.02 * 1e18).toString(),
expiryTime,
accounts[2],
[3000000, 3000001, 4000000, 4000001, 4000002],
[
[
[accounts[3], 8001],
[accounts[4], 2000],
],
[
[accounts[3], 8001],
[accounts[4], 2000],
],
[
[accounts[3], 9000],
[accounts[4], 2000],
],
[
[accounts[3], 9000],
[accounts[4], 2000],
],
[
[accounts[3], 8500],
[accounts[4], 2000],
],
],
false,
],
]
);
const hash = web3.utils.keccak256(signParams);
var sig = await web3.eth.sign(hash, this.signer);
sig = sig.substr(2);
const r = "0x" + sig.slice(0, 64);
const s = "0x" + sig.slice(64, 128);
const v = "0x" + sig.slice(128, 130);
// Generate signature

try {
await contract.startSale();
await contract.buyArtworks(
r,
s,
web3.utils.toDecimal(v) + 27, // magic 27
[
BigInt(0.25 * 1e18).toString(),
BigInt(0.02 * 1e18).toString(),
expiryTime,
accounts[2],
[3000000, 3000001, 4000000, 4000001, 4000002],
[
[
[accounts[3], 8001],
[accounts[4], 2000],
],
[
[accounts[3], 8001],
[accounts[4], 2000],
],
[
[accounts[3], 9000],
[accounts[4], 2000],
],
[
[accounts[3], 9000],
[accounts[4], 2000],
],
[
[accounts[3], 8500],
[accounts[4], 2000],
],
],
false,
],
{ from: accounts[5], value: 0.25 * 1e18 }
);
} catch (error) {
assert.ok(
error.message.includes(
"FeralfileExhibitionV4: total bps over 10,000"
)
);
}
});

it("test start/stop and burn, pause/resume sale", async function () {
const contract = this.contracts[4];

Expand Down

0 comments on commit a140159

Please sign in to comment.