Adding price to deposits and add token transfers
This commit is contained in:
@@ -5,33 +5,61 @@ 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 () {
|
||||
|
||||
[owner, wallet2, wallet3, wallet4] = await ethers.getSigners();
|
||||
|
||||
const ERC20Factory = await ethers.getContractFactory("MockToken");
|
||||
erc20 = await ERC20Factory.deploy(ethers.utils.parseEther('20000000', 'wei'));
|
||||
await erc20.deployed();
|
||||
|
||||
// Check initial balance
|
||||
expect(await erc20.balanceOf(owner.address)).to.equal(ethers.utils.parseEther('20000000', 'wei'));
|
||||
|
||||
const P2PIX = await ethers.getContractFactory("P2PIX");
|
||||
p2pix = await P2PIX.deploy(2, [owner.address, wallet2.address]);
|
||||
await p2pix.deployed();
|
||||
|
||||
// Verify values at deployment
|
||||
expect(await p2pix.validBacenSigners(owner.address)).to.equal(true);
|
||||
expect(await p2pix.validBacenSigners(wallet2.address)).to.equal(true);
|
||||
});
|
||||
|
||||
it("Should allow create a deposit", async function () {
|
||||
const transaction = await p2pix.deposit(ethers.constants.AddressZero, 1000, 'SELLER PIX KEY');
|
||||
depositID = ethers.utils.solidityKeccak256(['string', 'uint256'], ['SELLER PIX KEY', 1000])
|
||||
|
||||
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')
|
||||
)
|
||||
|
||||
transaction = await p2pix.deposit(
|
||||
erc20.address,
|
||||
ethers.utils.parseEther('1000'),
|
||||
ethers.utils.parseEther('0.99'),
|
||||
'SELLER PIX KEY'
|
||||
);
|
||||
depositID = ethers.utils.solidityKeccak256(['string', 'uint256'], ['SELLER PIX KEY', ethers.utils.parseEther('1000')])
|
||||
await expect(transaction).to.emit(p2pix, 'DepositAdded').withArgs(
|
||||
owner.address,
|
||||
depositID,
|
||||
ethers.constants.AddressZero,
|
||||
1000
|
||||
erc20.address,
|
||||
ethers.utils.parseEther('0.99'),
|
||||
ethers.utils.parseEther('1000')
|
||||
)
|
||||
})
|
||||
|
||||
it("Should prevent create same deposit", async function () {
|
||||
await expect(p2pix.deposit(ethers.constants.AddressZero, 1000, 'SELLER PIX KEY'))
|
||||
await expect(p2pix.deposit(
|
||||
erc20.address,
|
||||
ethers.utils.parseEther('1000'),
|
||||
ethers.utils.parseEther('0.99'),
|
||||
'SELLER PIX KEY'
|
||||
))
|
||||
.to.be.revertedWith('P2PIX: Deposit already exist and it is still valid');
|
||||
})
|
||||
|
||||
@@ -44,13 +72,27 @@ describe("P2PIX deposit test", function () {
|
||||
})
|
||||
|
||||
it("Should allow recreate the deposit", async function () {
|
||||
const transaction = await p2pix.deposit(ethers.constants.AddressZero, 1000, 'SELLER PIX KEY');
|
||||
depositID = ethers.utils.solidityKeccak256(['string', 'uint256'], ['SELLER PIX KEY', 1000])
|
||||
|
||||
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')
|
||||
)
|
||||
|
||||
transaction = await p2pix.deposit(
|
||||
erc20.address,
|
||||
ethers.utils.parseEther('1000'),
|
||||
ethers.utils.parseEther('0.99'),
|
||||
'SELLER PIX KEY'
|
||||
);
|
||||
depositID = ethers.utils.solidityKeccak256(['string', 'uint256'], ['SELLER PIX KEY', ethers.utils.parseEther('1000')])
|
||||
await expect(transaction).to.emit(p2pix, 'DepositAdded').withArgs(
|
||||
owner.address,
|
||||
depositID,
|
||||
ethers.constants.AddressZero,
|
||||
1000
|
||||
erc20.address,
|
||||
ethers.utils.parseEther('0.99'),
|
||||
ethers.utils.parseEther('1000')
|
||||
)
|
||||
})
|
||||
|
||||
@@ -67,7 +109,7 @@ describe("P2PIX deposit test", function () {
|
||||
await expect(transaction).to.emit(p2pix, 'DepositWithdrawn').withArgs(
|
||||
owner.address,
|
||||
depositID,
|
||||
1000
|
||||
ethers.utils.parseEther('1000')
|
||||
)
|
||||
})
|
||||
})
|
||||
78
test/2-lock-release.test.js
Normal file
78
test/2-lock-release.test.js
Normal file
@@ -0,0 +1,78 @@
|
||||
const { expect } = require("chai");
|
||||
const { ethers } = require("hardhat");
|
||||
|
||||
describe("P2PIX lock/release test", function () {
|
||||
|
||||
let owner, wallet2, wallet3, wallet4;
|
||||
let p2pix; // Contract instance
|
||||
let erc20; // Token instance
|
||||
let depositID;
|
||||
|
||||
it("Will deploy contracts", async function () {
|
||||
|
||||
[owner, wallet2, wallet3, wallet4] = await ethers.getSigners();
|
||||
|
||||
const ERC20Factory = await ethers.getContractFactory("MockToken");
|
||||
erc20 = await ERC20Factory.deploy(ethers.utils.parseEther('20000000', 'wei'));
|
||||
await erc20.deployed();
|
||||
|
||||
// Check initial balance
|
||||
expect(await erc20.balanceOf(owner.address)).to.equal(ethers.utils.parseEther('20000000', 'wei'));
|
||||
|
||||
const P2PIX = await ethers.getContractFactory("P2PIX");
|
||||
p2pix = await P2PIX.deploy(2, [owner.address, wallet2.address]);
|
||||
await p2pix.deployed();
|
||||
|
||||
// Verify values at deployment
|
||||
expect(await p2pix.validBacenSigners(owner.address)).to.equal(true);
|
||||
expect(await p2pix.validBacenSigners(wallet2.address)).to.equal(true);
|
||||
});
|
||||
|
||||
it("Should allow create a 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')
|
||||
)
|
||||
|
||||
transaction = await p2pix.deposit(
|
||||
erc20.address,
|
||||
ethers.utils.parseEther('1000'),
|
||||
ethers.utils.parseEther('0.99'),
|
||||
'SELLER PIX KEY'
|
||||
);
|
||||
depositID = ethers.utils.solidityKeccak256(['string', 'uint256'], ['SELLER PIX KEY', ethers.utils.parseEther('1000')])
|
||||
await expect(transaction).to.emit(p2pix, 'DepositAdded').withArgs(
|
||||
owner.address,
|
||||
depositID,
|
||||
erc20.address,
|
||||
ethers.utils.parseEther('0.99'),
|
||||
ethers.utils.parseEther('1000')
|
||||
)
|
||||
})
|
||||
|
||||
it("Should allow create a new lock", async function () {
|
||||
transaction = await p2pix.connect(wallet3).lock(
|
||||
depositID,
|
||||
wallet3.address,
|
||||
ethers.constants.AddressZero,
|
||||
'0',
|
||||
ethers.utils.parseEther('100'),
|
||||
[]
|
||||
)
|
||||
const lockID = ethers.utils.solidityKeccak256(['bytes32', 'uint256', 'address'], [
|
||||
depositID,
|
||||
ethers.utils.parseEther('100'),
|
||||
wallet3.address
|
||||
])
|
||||
await expect(transaction).to.emit(p2pix, 'LockAdded').withArgs(
|
||||
wallet3.address,
|
||||
lockID,
|
||||
depositID,
|
||||
ethers.utils.parseEther('100')
|
||||
)
|
||||
})
|
||||
|
||||
})
|
||||
Reference in New Issue
Block a user