update tests for current function parameters

This commit is contained in:
hueso 2024-02-29 19:53:12 -03:00
parent 1ffa9c6b5c
commit d27bdda15e
2 changed files with 4 additions and 171 deletions

View File

@ -37,9 +37,6 @@ import {
getSignerAddrs, getSignerAddrs,
p2pixFixture, p2pixFixture,
randomSigners, randomSigners,
createDepositArgs,
createLockArgs,
createReleaseArgs
} from "./utils/fixtures"; } from "./utils/fixtures";
describe("P2PIX", () => { describe("P2PIX", () => {
@ -319,11 +316,8 @@ describe("P2PIX", () => {
// amount: ethers.constants.One, // amount: ethers.constants.One,
// valid: true, // valid: true,
// }; // };
const txArgs = createDepositArgs(pTarget, root, owner.address, ethers.constants.One, true);
const tx = p2pix.deposit( const tx = p2pix.deposit(pTarget, root, owner.address, ethers.constants.One, true);
txArgs
);
await expect(tx).to.be.revertedWithCustomError( await expect(tx).to.be.revertedWithCustomError(
p2pix, p2pix,
@ -335,9 +329,7 @@ describe("P2PIX", () => {
ethers.utils.toUtf8Bytes("root"), ethers.utils.toUtf8Bytes("root"),
); );
const txArgs = createDepositArgs("", root, erc20.address, ethers.constants.One, true); const tx = p2pix.deposit("", root, erc20.address, ethers.constants.One, true);
const tx = p2pix.deposit(txArgs);
await expect(tx).to.be.revertedWithCustomError( await expect(tx).to.be.revertedWithCustomError(
p2pix, p2pix,
@ -349,8 +341,7 @@ describe("P2PIX", () => {
const root = ethers.utils.keccak256( const root = ethers.utils.keccak256(
ethers.utils.toUtf8Bytes("root"), ethers.utils.toUtf8Bytes("root"),
); );
const txArgs = createDepositArgs(pTarget, root, erc20.address, ethers.utils.parseEther("100000001"), true); const tx = p2pix.deposit(pTarget, root, erc20.address, ethers.utils.parseEther("100000001"), true);
const tx = p2pix.deposit(txArgs);
await expect(tx).to.be.revertedWithCustomError( await expect(tx).to.be.revertedWithCustomError(
p2pix, p2pix,
@ -364,13 +355,11 @@ describe("P2PIX", () => {
await erc20.approve(p2pix.address, price); await erc20.approve(p2pix.address, price);
const tx = await p2pix.deposit( const tx = await p2pix.deposit(
createDepositArgs(
pTarget, pTarget,
root, root,
erc20.address, erc20.address,
price, price,
true, true,
),
); );
const storage = await p2pix.callStatic.getBalance( const storage = await p2pix.callStatic.getBalance(
owner.address, owner.address,
@ -458,39 +447,33 @@ describe("P2PIX", () => {
const tx = await p2pix const tx = await p2pix
.connect(owner) .connect(owner)
.deposit(createDepositArgs(pTarget, root, erc20.address, price, true)); .deposit(pTarget, root, erc20.address, price, true);
const tx2 = await p2pix const tx2 = await p2pix
.connect(acc01) .connect(acc01)
.deposit( .deposit(
createDepositArgs(
pTarget2, pTarget2,
nullRoot, nullRoot,
erc20.address, erc20.address,
price2, price2,
false, false,
),
); );
const tx3 = await p2pix const tx3 = await p2pix
.connect(acc02) .connect(acc02)
.deposit( .deposit(
createDepositArgs(
pTarget3, pTarget3,
root, root,
erc20.address, erc20.address,
price3, price3,
true, true,
),
); );
const tx4 = await p2pix const tx4 = await p2pix
.connect(acc03) .connect(acc03)
.deposit( .deposit(
createDepositArgs(
pTarget, pTarget,
nullRoot, nullRoot,
erc20.address, erc20.address,
price4, price4,
false, false,
),
); );
const balances = await p2pix.callStatic.getBalances( const balances = await p2pix.callStatic.getBalances(
@ -628,34 +611,28 @@ describe("P2PIX", () => {
const pTarget = "7ce3339x4133301u8f63pn71a5333118"; const pTarget = "7ce3339x4133301u8f63pn71a5333118";
await erc20.approve(p2pix.address, price); await erc20.approve(p2pix.address, price);
await p2pix.deposit( await p2pix.deposit(
createDepositArgs(
pTarget, pTarget,
ethers.constants.HashZero, ethers.constants.HashZero,
erc20.address, erc20.address,
price, price,
true, true,
),
); );
await p2pix.setValidState(erc20.address, false); await p2pix.setValidState(erc20.address, false);
const fail = p2pix const fail = p2pix
.connect(acc03) .connect(acc03)
.lock( .lock(
createLockArgs(
owner.address, owner.address,
erc20.address, erc20.address,
price, price,
[], [],
[], [],
),
); );
const fail2 = p2pix.lock( const fail2 = p2pix.lock(
createLockArgs(
zero, zero,
zero, zero,
price, price,
[], [],
[], [],
),
); );
await expect(fail).to.be.revertedWithCustomError( await expect(fail).to.be.revertedWithCustomError(
@ -671,24 +648,20 @@ describe("P2PIX", () => {
await erc20.approve(p2pix.address, price); await erc20.approve(p2pix.address, price);
const pTarget = "7ce3339x4133301u8f63pn71a5333118"; const pTarget = "7ce3339x4133301u8f63pn71a5333118";
await p2pix.deposit( await p2pix.deposit(
createDepositArgs(
pTarget, pTarget,
ethers.constants.HashZero, ethers.constants.HashZero,
erc20.address, erc20.address,
price, price,
true, true,
),
); );
const fail = p2pix const fail = p2pix
.connect(acc03) .connect(acc03)
.lock( .lock(
createLockArgs(
owner.address, owner.address,
erc20.address, erc20.address,
price.mul(ethers.BigNumber.from(2)), price.mul(ethers.BigNumber.from(2)),
[], [],
[], [],
),
); );
await expect(fail).to.be.revertedWithCustomError( await expect(fail).to.be.revertedWithCustomError(
@ -700,24 +673,20 @@ describe("P2PIX", () => {
it("should revert if an invalid allowlist merkleproof is provided", async () => { it("should revert if an invalid allowlist merkleproof is provided", async () => {
await erc20.approve(p2pix.address, price); await erc20.approve(p2pix.address, price);
await p2pix.deposit( await p2pix.deposit(
createDepositArgs(
"7ce3339x4133301u8f63pn71a5333118", "7ce3339x4133301u8f63pn71a5333118",
merkleRoot, merkleRoot,
erc20.address, erc20.address,
price, price,
true, true,
),
); );
const fail = p2pix const fail = p2pix
.connect(acc02) .connect(acc02)
.lock( .lock(
createLockArgs(
owner.address, owner.address,
erc20.address, erc20.address,
ethers.BigNumber.from(1000), ethers.BigNumber.from(1000),
[ethers.utils.keccak256(ethers.utils.toUtf8Bytes("wrong"))], [ethers.utils.keccak256(ethers.utils.toUtf8Bytes("wrong"))],
[], [],
),
); );
await expect(fail).to.be.revertedWithCustomError( await expect(fail).to.be.revertedWithCustomError(
@ -731,24 +700,20 @@ describe("P2PIX", () => {
price.mul(BigNumber.from("3")), price.mul(BigNumber.from("3")),
); );
await p2pix.deposit( await p2pix.deposit(
createDepositArgs(
"1", "1",
merkleRoot, merkleRoot,
erc20.address, erc20.address,
price.mul(BigNumber.from("3")), price.mul(BigNumber.from("3")),
true, true,
),
); );
const fail = p2pix const fail = p2pix
.connect(acc02) .connect(acc02)
.lock( .lock(
createLockArgs(
owner.address, owner.address,
erc20.address, erc20.address,
price.mul(BigNumber.from("2")), price.mul(BigNumber.from("2")),
[], [],
[], [],
),
); );
await expect(fail).to.be.revertedWithCustomError( await expect(fail).to.be.revertedWithCustomError(
@ -760,24 +725,20 @@ describe("P2PIX", () => {
const target = "333"; const target = "333";
await erc20.approve(p2pix.address, price); await erc20.approve(p2pix.address, price);
await p2pix.deposit( await p2pix.deposit(
createDepositArgs(
target, target,
merkleRoot, merkleRoot,
erc20.address, erc20.address,
price, price,
true, true,
),
); );
const tx = await p2pix const tx = await p2pix
.connect(acc01) .connect(acc01)
.lock( .lock(
createLockArgs(
owner.address, owner.address,
erc20.address, erc20.address,
price, price,
proof, proof,
[], [],
),
); );
const storage: Lock = await p2pix.callStatic.mapLocks( const storage: Lock = await p2pix.callStatic.mapLocks(
1, 1,
@ -808,24 +769,20 @@ describe("P2PIX", () => {
const target = "101"; const target = "101";
await erc20.approve(p2pix.address, price); await erc20.approve(p2pix.address, price);
await p2pix.deposit( await p2pix.deposit(
createDepositArgs(
target, target,
root, root,
erc20.address, erc20.address,
price, price,
true, true,
),
); );
const tx = await p2pix const tx = await p2pix
.connect(acc01) .connect(acc01)
.lock( .lock(
createLockArgs(
owner.address, owner.address,
erc20.address, erc20.address,
price, price,
[], [],
[], [],
),
); );
const storage: Lock = await p2pix.callStatic.mapLocks( const storage: Lock = await p2pix.callStatic.mapLocks(
1, 1,
@ -873,44 +830,36 @@ describe("P2PIX", () => {
// const sig = ethers.utils.splitSignature(flatSig); // const sig = ethers.utils.splitSignature(flatSig);
await erc20.approve(p2pix.address, newPrice); await erc20.approve(p2pix.address, newPrice);
await p2pix.deposit( await p2pix.deposit(
createDepositArgs(
target, target,
root, root,
erc20.address, erc20.address,
newPrice, newPrice,
true, true,
),
); );
await p2pix await p2pix
.connect(acc01) .connect(acc01)
.lock( .lock(
createLockArgs(
owner.address, owner.address,
erc20.address, erc20.address,
price, price,
[], [],
[], [],
),
); );
await p2pix await p2pix
.connect(acc01) .connect(acc01)
.release( .release(
createReleaseArgs(
ethers.constants.One, ethers.constants.One,
endtoendID, endtoendID,
flatSig flatSig
),
); );
const tx = await p2pix const tx = await p2pix
.connect(acc01) .connect(acc01)
.lock( .lock(
createLockArgs(
owner.address, owner.address,
erc20.address, erc20.address,
price.add(ethers.constants.One), price.add(ethers.constants.One),
[], [],
[], [],
),
); );
const storage: Lock = await p2pix.callStatic.mapLocks( const storage: Lock = await p2pix.callStatic.mapLocks(
2, 2,
@ -947,24 +896,20 @@ describe("P2PIX", () => {
const target = ethers.BigNumber.from(101).toString(); const target = ethers.BigNumber.from(101).toString();
await erc20.approve(p2pix.address, price); await erc20.approve(p2pix.address, price);
await p2pix.deposit( await p2pix.deposit(
createDepositArgs(
target, target,
merkleRoot, merkleRoot,
erc20.address, erc20.address,
price, price,
true, true,
),
); );
const tx1 = await p2pix const tx1 = await p2pix
.connect(acc01) .connect(acc01)
.lock( .lock(
createLockArgs(
owner.address, owner.address,
erc20.address, erc20.address,
newPrice, newPrice,
proof, proof,
[], [],
),
); );
const storage1: Lock = await p2pix.callStatic.mapLocks( const storage1: Lock = await p2pix.callStatic.mapLocks(
1, 1,
@ -976,13 +921,11 @@ describe("P2PIX", () => {
const tx2 = await p2pix const tx2 = await p2pix
.connect(acc01) .connect(acc01)
.lock( .lock(
createLockArgs(
owner.address, owner.address,
erc20.address, erc20.address,
ethers.BigNumber.from(100), ethers.BigNumber.from(100),
[], [],
[], [],
),
); );
const storage2: Lock = await p2pix.callStatic.mapLocks( const storage2: Lock = await p2pix.callStatic.mapLocks(
2, 2,
@ -994,13 +937,11 @@ describe("P2PIX", () => {
const tx3 = await p2pix const tx3 = await p2pix
.connect(acc03) .connect(acc03)
.lock( .lock(
createLockArgs(
owner.address, owner.address,
erc20.address, erc20.address,
ethers.BigNumber.from(100), ethers.BigNumber.from(100),
[], [],
[], [],
),
); );
const storage3: Lock = await p2pix.callStatic.mapLocks( const storage3: Lock = await p2pix.callStatic.mapLocks(
3, 3,
@ -1133,13 +1074,11 @@ describe("P2PIX", () => {
it("should setValidState, update storage and emit events", async () => { it("should setValidState, update storage and emit events", async () => {
await erc20.approve(p2pix.address, price); await erc20.approve(p2pix.address, price);
await p2pix.deposit( await p2pix.deposit(
createDepositArgs(
ethers.BigNumber.from(10101).toString(), ethers.BigNumber.from(10101).toString(),
merkleRoot, merkleRoot,
erc20.address, erc20.address,
price, price,
true, true,
),
); );
const state1 = await p2pix.callStatic.getValid( const state1 = await p2pix.callStatic.getValid(
owner.address, owner.address,
@ -1167,13 +1106,11 @@ describe("P2PIX", () => {
const target = ethers.BigNumber.from("1").toString(); const target = ethers.BigNumber.from("1").toString();
await erc20.approve(p2pix.address, price); await erc20.approve(p2pix.address, price);
await p2pix.deposit( await p2pix.deposit(
createDepositArgs(
target, target,
hashZero, hashZero,
erc20.address, erc20.address,
price, price,
true, true,
),
); );
await erc20 await erc20
.connect(acc01) .connect(acc01)
@ -1181,13 +1118,11 @@ describe("P2PIX", () => {
await p2pix await p2pix
.connect(acc01) .connect(acc01)
.deposit( .deposit(
createDepositArgs(
target, target,
hashZero, hashZero,
erc20.address, erc20.address,
price, price,
false, false,
),
); );
await erc20 await erc20
.connect(acc02) .connect(acc02)
@ -1195,13 +1130,11 @@ describe("P2PIX", () => {
await p2pix await p2pix
.connect(acc02) .connect(acc02)
.deposit( .deposit(
createDepositArgs(
target, target,
hashZero, hashZero,
erc20.address, erc20.address,
price, price,
true, true,
),
); );
const oldState1 = await p2pix.callStatic.getValid( const oldState1 = await p2pix.callStatic.getValid(
owner.address, owner.address,
@ -1271,33 +1204,27 @@ describe("P2PIX", () => {
// const sig = ethers.utils.splitSignature(flatSig); // const sig = ethers.utils.splitSignature(flatSig);
await erc20.approve(p2pix.address, price); await erc20.approve(p2pix.address, price);
await p2pix.deposit( await p2pix.deposit(
createDepositArgs(
target, target,
merkleRoot, merkleRoot,
erc20.address, erc20.address,
price, price,
true, true,
),
); );
await p2pix await p2pix
.connect(acc03) .connect(acc03)
.lock( .lock(
createLockArgs(
owner.address, owner.address,
erc20.address, erc20.address,
ethers.BigNumber.from(100), ethers.BigNumber.from(100),
[], [],
[], [],
),
); );
const lockID = ethers.constants.One; const lockID = ethers.constants.One;
await mine(13); await mine(13);
const fail = p2pix.release( const fail = p2pix.release(
createReleaseArgs(
lockID, lockID,
ethers.constants.HashZero, ethers.constants.HashZero,
flatSig, flatSig,
),
); );
await expect(fail).to.be.revertedWithCustomError( await expect(fail).to.be.revertedWithCustomError(
@ -1318,39 +1245,31 @@ describe("P2PIX", () => {
// const sig = ethers.utils.splitSignature(flatSig); // const sig = ethers.utils.splitSignature(flatSig);
await erc20.approve(p2pix.address, price); await erc20.approve(p2pix.address, price);
await p2pix.deposit( await p2pix.deposit(
createDepositArgs(
target, target,
merkleRoot, merkleRoot,
erc20.address, erc20.address,
price, price,
true, true,
),
); );
await p2pix await p2pix
.connect(acc03) .connect(acc03)
.lock( .lock(
createLockArgs(
owner.address, owner.address,
erc20.address, erc20.address,
ethers.BigNumber.from(100), ethers.BigNumber.from(100),
[], [],
[], [],
),
); );
const lockID = ethers.constants.One; const lockID = ethers.constants.One;
await p2pix.release( await p2pix.release(
createReleaseArgs(
lockID, lockID,
ethers.constants.HashZero, ethers.constants.HashZero,
flatSig flatSig
),
); );
const fail = p2pix.release( const fail = p2pix.release(
createReleaseArgs(
lockID, lockID,
ethers.constants.HashZero, ethers.constants.HashZero,
flatSig, flatSig,
),
); );
await expect(fail).to.be.revertedWithCustomError( await expect(fail).to.be.revertedWithCustomError(
@ -1370,54 +1289,44 @@ describe("P2PIX", () => {
// const sig = ethers.utils.splitSignature(flatSig); // const sig = ethers.utils.splitSignature(flatSig);
await erc20.approve(p2pix.address, price); await erc20.approve(p2pix.address, price);
await p2pix.deposit( await p2pix.deposit(
createDepositArgs(
target, target,
ethers.constants.HashZero, ethers.constants.HashZero,
erc20.address, erc20.address,
price, price,
true, true,
),
); );
await p2pix await p2pix
.connect(acc03) .connect(acc03)
.lock( .lock(
createLockArgs(
owner.address, owner.address,
erc20.address, erc20.address,
ethers.BigNumber.from(100), ethers.BigNumber.from(100),
[], [],
[], [],
),
); );
await p2pix await p2pix
.connect(acc01) .connect(acc01)
.release( .release(
createReleaseArgs(
ethers.constants.One, ethers.constants.One,
ethers.constants.HashZero, ethers.constants.HashZero,
flatSig, flatSig,
),
); );
await p2pix await p2pix
.connect(acc03) .connect(acc03)
.lock( .lock(
createLockArgs(
owner.address, owner.address,
erc20.address, erc20.address,
ethers.BigNumber.from(100), ethers.BigNumber.from(100),
[], [],
[], [],
),
); );
const fail = p2pix const fail = p2pix
.connect(acc01) .connect(acc01)
.release( .release(
createReleaseArgs(
ethers.constants.Two, ethers.constants.Two,
ethers.constants.HashZero, ethers.constants.HashZero,
flatSig, flatSig,
),
); );
await expect(fail).to.be.revertedWithCustomError( await expect(fail).to.be.revertedWithCustomError(
@ -1438,33 +1347,27 @@ describe("P2PIX", () => {
await erc20.approve(p2pix.address, price); await erc20.approve(p2pix.address, price);
await p2pix.deposit( await p2pix.deposit(
createDepositArgs(
target, target,
ethers.constants.HashZero, ethers.constants.HashZero,
erc20.address, erc20.address,
price, price,
true, true,
),
); );
await p2pix await p2pix
.connect(acc03) .connect(acc03)
.lock( .lock(
createLockArgs(
owner.address, owner.address,
erc20.address, erc20.address,
ethers.BigNumber.from(100), ethers.BigNumber.from(100),
[], [],
[], [],
),
); );
const fail = p2pix const fail = p2pix
.connect(acc01) .connect(acc01)
.release( .release(
createReleaseArgs(
ethers.constants.One, ethers.constants.One,
ethers.constants.HashZero, ethers.constants.HashZero,
flatSig, flatSig,
),
); );
await expect(fail).to.be.revertedWithCustomError( await expect(fail).to.be.revertedWithCustomError(
@ -1500,24 +1403,20 @@ describe("P2PIX", () => {
await erc20.approve(p2pix.address, price); await erc20.approve(p2pix.address, price);
await p2pix.deposit( await p2pix.deposit(
createDepositArgs(
pixTarget, pixTarget,
root, root,
erc20.address, erc20.address,
price, price,
true, true,
),
); );
await p2pix await p2pix
.connect(acc03) .connect(acc03)
.lock( .lock(
createLockArgs(
owner.address, owner.address,
erc20.address, erc20.address,
ethers.BigNumber.from(100), ethers.BigNumber.from(100),
[], [],
[], [],
),
); );
const acc01Key = await p2pix.callStatic._castAddrToKey( const acc01Key = await p2pix.callStatic._castAddrToKey(
acc01.address, acc01.address,
@ -1537,11 +1436,9 @@ describe("P2PIX", () => {
const tx = await p2pix const tx = await p2pix
.connect(acc01) .connect(acc01)
.release( .release(
createReleaseArgs(
ethers.constants.One, ethers.constants.One,
endtoendID, endtoendID,
flatSig, flatSig,
),
); );
const lockStatus1 = const lockStatus1 =
@ -1670,46 +1567,38 @@ describe("P2PIX", () => {
// const sig3 = ethers.utils.splitSignature(flatSig3); // const sig3 = ethers.utils.splitSignature(flatSig3);
await erc20.approve(p2pix.address, price); await erc20.approve(p2pix.address, price);
await p2pix.deposit( await p2pix.deposit(
createDepositArgs(
pixTarget, pixTarget,
root, root,
erc20.address, erc20.address,
price, price,
true, true,
),
); );
await p2pix await p2pix
.connect(acc03) .connect(acc03)
.lock( .lock(
createLockArgs(
owner.address, owner.address,
erc20.address, erc20.address,
ethers.BigNumber.from(100), ethers.BigNumber.from(100),
[], [],
[], [],
),
); );
await p2pix await p2pix
.connect(acc03) .connect(acc03)
.lock( .lock(
createLockArgs(
owner.address, owner.address,
erc20.address, erc20.address,
ethers.BigNumber.from(50), ethers.BigNumber.from(50),
[], [],
[], [],
),
); );
await p2pix await p2pix
.connect(acc03) .connect(acc03)
.lock( .lock(
createLockArgs(
owner.address, owner.address,
erc20.address, erc20.address,
ethers.BigNumber.from(25), ethers.BigNumber.from(25),
[], [],
[], [],
),
); );
const lockStatus1 = const lockStatus1 =
@ -1740,33 +1629,27 @@ describe("P2PIX", () => {
const tx = await p2pix const tx = await p2pix
.connect(acc01) .connect(acc01)
.release( .release(
createReleaseArgs(
lockID, lockID,
endtoendID, endtoendID,
flatSig1, flatSig1,
),
); );
// relayerPremium != 0 && // relayerPremium != 0 &&
// lock's msg.sender != release's msg.sender // lock's msg.sender != release's msg.sender
const tx1 = await p2pix const tx1 = await p2pix
.connect(acc01) .connect(acc01)
.release( .release(
createReleaseArgs(
lockID2, lockID2,
endtoendID, endtoendID,
flatSig2, flatSig2,
),
); );
// relayerPremium != 0 && // relayerPremium != 0 &&
// lock's msg.sender == release's msg.sender // lock's msg.sender == release's msg.sender
const tx2 = await p2pix const tx2 = await p2pix
.connect(acc03) .connect(acc03)
.release( .release(
createReleaseArgs(
lockID3, lockID3,
endtoendID, endtoendID,
flatSig3, flatSig3,
),
); );
const used1 = await p2pix.callStatic.usedTransactions( const used1 = await p2pix.callStatic.usedTransactions(
ethers.utils.arrayify(messageToSign1), ethers.utils.arrayify(messageToSign1),
@ -1871,24 +1754,20 @@ describe("P2PIX", () => {
const target = ethers.BigNumber.from(101).toString(); const target = ethers.BigNumber.from(101).toString();
await erc20.approve(p2pix.address, price); await erc20.approve(p2pix.address, price);
await p2pix.deposit( await p2pix.deposit(
createDepositArgs(
target, target,
merkleRoot, merkleRoot,
erc20.address, erc20.address,
price, price,
true, true,
),
); );
await p2pix await p2pix
.connect(acc02) .connect(acc02)
.lock( .lock(
createLockArgs(
owner.address, owner.address,
erc20.address, erc20.address,
ethers.constants.One, ethers.constants.One,
[], [],
[], [],
),
); );
const lockID = ethers.constants.One; const lockID = ethers.constants.One;
const fail = p2pix.unlockExpired([lockID]); const fail = p2pix.unlockExpired([lockID]);
@ -1913,33 +1792,27 @@ describe("P2PIX", () => {
// const sig = ethers.utils.splitSignature(flatSig); // const sig = ethers.utils.splitSignature(flatSig);
await erc20.approve(p2pix.address, price); await erc20.approve(p2pix.address, price);
await p2pix.deposit( await p2pix.deposit(
createDepositArgs(
pixTarget, pixTarget,
merkleRoot, merkleRoot,
erc20.address, erc20.address,
price, price,
true, true,
),
); );
await p2pix await p2pix
.connect(acc02) .connect(acc02)
.lock( .lock(
createLockArgs(
owner.address, owner.address,
erc20.address, erc20.address,
ethers.constants.One, ethers.constants.One,
[], [],
[], [],
),
); );
const lockID = ethers.constants.One; const lockID = ethers.constants.One;
// await mine(10); // await mine(10);
await p2pix.release( await p2pix.release(
createReleaseArgs(
lockID, lockID,
endtoendID, endtoendID,
flatSig, flatSig,
),
); );
const fail = p2pix.unlockExpired([lockID]); const fail = p2pix.unlockExpired([lockID]);
@ -1952,24 +1825,20 @@ describe("P2PIX", () => {
const target = ethers.BigNumber.from(101).toString(); const target = ethers.BigNumber.from(101).toString();
await erc20.approve(p2pix.address, price); await erc20.approve(p2pix.address, price);
await p2pix.deposit( await p2pix.deposit(
createDepositArgs(
target, target,
merkleRoot, merkleRoot,
erc20.address, erc20.address,
price, price,
true, true,
),
); );
await p2pix await p2pix
.connect(acc02) .connect(acc02)
.lock( .lock(
createLockArgs(
owner.address, owner.address,
erc20.address, erc20.address,
ethers.constants.One, ethers.constants.One,
[], [],
[], [],
),
); );
const lockID = ethers.constants.One; const lockID = ethers.constants.One;
await mine(11); await mine(11);
@ -2019,24 +1888,20 @@ describe("P2PIX", () => {
// test method through lock fx // test method through lock fx
await erc20.approve(p2pix.address, price); await erc20.approve(p2pix.address, price);
await p2pix.deposit( await p2pix.deposit(
createDepositArgs(
target, target,
merkleRoot, merkleRoot,
erc20.address, erc20.address,
price, price,
true, true,
),
); );
const lock1: ContractTransaction = await p2pix const lock1: ContractTransaction = await p2pix
.connect(acc01) .connect(acc01)
.lock( .lock(
createLockArgs(
owner.address, owner.address,
erc20.address, erc20.address,
price, price,
proof, proof,
[], [],
),
); );
// as return values of non view functions can't be accessed // as return values of non view functions can't be accessed
// outside the evm, we fetch the lockID from the emitted event. // outside the evm, we fetch the lockID from the emitted event.
@ -2071,13 +1936,11 @@ describe("P2PIX", () => {
// create another lock by freeing the price value // create another lock by freeing the price value
// back to `l.remamining` and lock 100 again. // back to `l.remamining` and lock 100 again.
const tx1 = await p2pix.lock( const tx1 = await p2pix.lock(
createLockArgs(
owner.address, owner.address,
erc20.address, erc20.address,
ethers.BigNumber.from(100), ethers.BigNumber.from(100),
[], [],
[lockID], [lockID],
),
); );
const remaining = await p2pix.callStatic.getBalance( const remaining = await p2pix.callStatic.getBalance(
owner.address, owner.address,
@ -2097,24 +1960,20 @@ describe("P2PIX", () => {
// test method through withdraw fx // test method through withdraw fx
await erc20.approve(p2pix.address, price); await erc20.approve(p2pix.address, price);
await p2pix.deposit( await p2pix.deposit(
createDepositArgs(
target, target,
merkleRoot, merkleRoot,
erc20.address, erc20.address,
price, price,
true, true,
),
); );
await p2pix await p2pix
.connect(acc01) .connect(acc01)
.lock( .lock(
createLockArgs(
owner.address, owner.address,
erc20.address, erc20.address,
price, price,
proof, proof,
[], [],
),
); );
const lockID = ethers.constants.One; const lockID = ethers.constants.One;
// mine blocks to expire lock // mine blocks to expire lock
@ -2140,13 +1999,11 @@ describe("P2PIX", () => {
const target = ethers.BigNumber.from(101).toString(); const target = ethers.BigNumber.from(101).toString();
await erc20.approve(p2pix.address, price); await erc20.approve(p2pix.address, price);
await p2pix.deposit( await p2pix.deposit(
createDepositArgs(
target, target,
merkleRoot, merkleRoot,
erc20.address, erc20.address,
price, price,
true, true,
),
); );
const fail = p2pix const fail = p2pix
.connect(acc02) .connect(acc02)
@ -2165,13 +2022,11 @@ describe("P2PIX", () => {
const newPrice = price.div(ethers.constants.Two); const newPrice = price.div(ethers.constants.Two);
await erc20.approve(p2pix.address, price); await erc20.approve(p2pix.address, price);
const dep = await p2pix.deposit( const dep = await p2pix.deposit(
createDepositArgs(
ethers.BigNumber.from(101).toString(), ethers.BigNumber.from(101).toString(),
merkleRoot, merkleRoot,
erc20.address, erc20.address,
price, price,
true, true,
),
); );
const tx = await p2pix.withdraw( const tx = await p2pix.withdraw(
erc20.address, erc20.address,

View File

@ -16,28 +16,6 @@ import { Call, RepFixture, P2PixAndReputation, DepositArgs, LockArgs, ReleaseArg
// exported constants // exported constants
export const createDepositArgs = (pixTarget: string, allowlistRoot: string, token: string, amount: BigNumber, valid:boolean): DepositArgs => ({
pixTarget,
allowlistRoot,
token,
amount,
valid,
});
export const createLockArgs = (seller: string, token: string, amount: BigNumber, merkleProof: string[], expiredLocks: BigNumber[]): LockArgs => ({
seller,
token,
amount,
merkleProof,
expiredLocks,
});
export const createReleaseArgs = (lockID: BigNumber, pixTimestamp: string, signature: string): ReleaseArgs => ({
lockID,
pixTimestamp,
signature,
});
export const getSignerAddrs = ( export const getSignerAddrs = (
amount: number, amount: number,
addrs: SignerWithAddress[], addrs: SignerWithAddress[],