Replace bytes32 ids on deposits for uint256 counters.

This commit is contained in:
Filipe Soccol
2022-11-11 16:10:57 -03:00
parent 5c5327eedd
commit 67f9cbb9a7
5 changed files with 77 additions and 89 deletions

View File

@@ -6,7 +6,6 @@ describe("P2PIX deposit test", function () {
let owner, wallet2, wallet3, wallet4;
let p2pix; // Contract instance
let erc20; // Token instance
let depositID;
it("Will deploy contracts", async function () {
@@ -30,11 +29,11 @@ describe("P2PIX deposit test", function () {
it("Should allow create a deposit", async function () {
let transaction = await erc20.approve(p2pix.address,ethers.utils.parseEther('1000'));
let transaction = await erc20.approve(p2pix.address,ethers.utils.parseEther('2000'));
await expect(transaction).to.emit(erc20, 'Approval').withArgs(
owner.address,
p2pix.address,
ethers.utils.parseEther('1000')
ethers.utils.parseEther('2000')
)
transaction = await p2pix.deposit(
@@ -43,72 +42,44 @@ describe("P2PIX deposit test", function () {
'SELLER PIX KEY',
{value:ethers.utils.parseEther('0.1')}
);
depositID = ethers.utils.solidityKeccak256(['string', 'uint256'], ['SELLER PIX KEY', ethers.utils.parseEther('1000')])
await expect(transaction).to.emit(p2pix, 'DepositAdded').withArgs(
owner.address,
depositID,
0,
erc20.address,
ethers.utils.parseEther('0.1'),
ethers.utils.parseEther('1000')
)
})
it("Should prevent create same deposit", async function () {
await expect(p2pix.deposit(
erc20.address,
ethers.utils.parseEther('1000'),
'SELLER PIX KEY',
{value:ethers.utils.parseEther('0.1')}
))
.to.be.revertedWith('P2PIX: Deposit already exist and it is still valid');
})
it("Should allow cancel the deposit", async function () {
const transaction = await p2pix.cancelDeposit(depositID);
await expect(transaction).to.emit(p2pix, 'DepositClosed').withArgs(
owner.address,
depositID
)
})
it("Should allow recreate the deposit", async function () {
let transaction = await erc20.approve(p2pix.address,ethers.utils.parseEther('1000'));
await expect(transaction).to.emit(erc20, 'Approval').withArgs(
owner.address,
p2pix.address,
ethers.utils.parseEther('1000')
)
it("Should allow create second deposit", async function () {
transaction = await p2pix.deposit(
erc20.address,
ethers.utils.parseEther('1000'),
'SELLER PIX KEY',
{value:ethers.utils.parseEther('0.1')}
);
depositID = ethers.utils.solidityKeccak256(['string', 'uint256'], ['SELLER PIX KEY', ethers.utils.parseEther('1000')])
)
await expect(transaction).to.emit(p2pix, 'DepositAdded').withArgs(
owner.address,
depositID,
1,
erc20.address,
ethers.utils.parseEther('0.1'),
ethers.utils.parseEther('1000')
)
})
it("Should allow cancel the deposit again", async function () {
const transaction = await p2pix.cancelDeposit(depositID);
it("Should allow cancel first deposit", async function () {
const transaction = await p2pix.cancelDeposit(0);
await expect(transaction).to.emit(p2pix, 'DepositClosed').withArgs(
owner.address,
depositID
0
)
})
it("Should allow withdraw the deposit", async function () {
const transaction = await p2pix.withdraw(depositID, []);
const transaction = await p2pix.withdraw(0, []);
await expect(transaction).to.emit(p2pix, 'DepositWithdrawn').withArgs(
owner.address,
depositID,
0,
ethers.utils.parseEther('1000')
)
})

View File

@@ -6,7 +6,7 @@ describe("P2PIX lock/release test", function () {
let owner, wallet2, wallet3, wallet4;
let p2pix; // Contract instance
let erc20; // Token instance
let depositID, lockID;
let lockID;
it("Will deploy contracts", async function () {
@@ -44,10 +44,9 @@ describe("P2PIX lock/release test", function () {
'SELLER PIX KEY',
{value:ethers.utils.parseEther('0.1')}
);
depositID = ethers.utils.solidityKeccak256(['string', 'uint256'], ['SELLER PIX KEY', ethers.utils.parseEther('1000')])
await expect(transaction).to.emit(p2pix, 'DepositAdded').withArgs(
owner.address,
depositID,
0,
erc20.address,
ethers.utils.parseEther('0.1'),
ethers.utils.parseEther('1000')
@@ -57,22 +56,22 @@ describe("P2PIX lock/release test", function () {
it("Should allow create a new lock", async function () {
transaction = await p2pix.connect(wallet3).lock(
depositID,
0,
wallet3.address,
ethers.constants.AddressZero,
'0',
ethers.utils.parseEther('100'),
[]
)
lockID = ethers.utils.solidityKeccak256(['bytes32', 'uint256', 'address'], [
depositID,
lockID = ethers.utils.solidityKeccak256(['uint256', 'uint256', 'address'], [
0,
ethers.utils.parseEther('100'),
wallet3.address
])
await expect(transaction).to.emit(p2pix, 'LockAdded').withArgs(
wallet3.address,
lockID,
depositID,
0,
ethers.utils.parseEther('100')
)
console.log('GAS USED:', (await transaction.wait()).cumulativeGasUsed.toString())
@@ -117,29 +116,29 @@ describe("P2PIX lock/release test", function () {
it("Should allow recreate same lock", async function () {
transaction = await p2pix.connect(wallet3).lock(
depositID,
0,
wallet3.address,
ethers.constants.AddressZero,
'0',
ethers.utils.parseEther('100'),
[]
)
lockID = ethers.utils.solidityKeccak256(['bytes32', 'uint256', 'address'], [
depositID,
lockID = ethers.utils.solidityKeccak256(['uint256', 'uint256', 'address'], [
0,
ethers.utils.parseEther('100'),
wallet3.address
])
await expect(transaction).to.emit(p2pix, 'LockAdded').withArgs(
wallet3.address,
lockID,
depositID,
0,
ethers.utils.parseEther('100'),
)
})
it("Should prevent create again same lock", async function () {
await expect(p2pix.connect(wallet3).lock(
depositID,
0,
wallet3.address,
ethers.constants.AddressZero,
'0',
@@ -187,9 +186,9 @@ describe("P2PIX lock/release test", function () {
)).to.be.revertedWith('P2PIX: Lock already released or returned');
})
it("Should prevent create a 800 lock", async function () {
it("Should prevent create a 900 lock", async function () {
await expect(p2pix.connect(wallet3).lock(
depositID,
0,
wallet3.address,
ethers.constants.AddressZero,
'0',
@@ -200,22 +199,22 @@ describe("P2PIX lock/release test", function () {
it("Should allow recreate same lock again", async function () {
transaction = await p2pix.connect(wallet3).lock(
depositID,
0,
wallet3.address,
ethers.constants.AddressZero,
'0',
ethers.utils.parseEther('100'),
[]
)
lockID = ethers.utils.solidityKeccak256(['bytes32', 'uint256', 'address'], [
depositID,
lockID = ethers.utils.solidityKeccak256(['uint256', 'uint256', 'address'], [
0,
ethers.utils.parseEther('100'),
wallet3.address
])
await expect(transaction).to.emit(p2pix, 'LockAdded').withArgs(
wallet3.address,
lockID,
depositID,
0,
ethers.utils.parseEther('100')
)
})