-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Chris Lahaye <[email protected]>
- Loading branch information
1 parent
e60cc4b
commit 2cd2cf1
Showing
2 changed files
with
176 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
// SPDX-License-Identifier: MIT | ||
|
||
pragma solidity ^0.8.0; | ||
|
||
import "./GatewayV1Call.sol"; | ||
import "./PassportV1.sol"; | ||
|
||
contract PassportV1AsyncMock is GatewayV1Call, PassportV1 { | ||
function initialize( | ||
address callAddress, | ||
string memory name, | ||
string memory symbol, | ||
uint256 priceAmount, | ||
AggregatorV3Interface priceFeed1, | ||
AggregatorV3Interface priceFeed2, | ||
address payable treasury, | ||
IDrawerV1 drawer | ||
) public initializer { | ||
__GatewayV1Call_init(callAddress); | ||
__PassportV1_init( | ||
name, | ||
symbol, | ||
priceAmount, | ||
priceFeed1, | ||
priceFeed2, | ||
treasury, | ||
drawer | ||
); | ||
|
||
_setupRole(DEFAULT_ADMIN_ROLE, _msgSender()); | ||
} | ||
|
||
function supportsInterface( | ||
bytes4 interfaceId | ||
) | ||
public | ||
view | ||
override(AccessControlUpgradeable, PassportV1) | ||
returns (bool) | ||
{ | ||
return super.supportsInterface(interfaceId); | ||
} | ||
|
||
function _callContract( | ||
bytes32 method, | ||
bytes memory params, | ||
uint256, | ||
address | ||
) internal override { | ||
GatewayV1Call._callContract(method, params); | ||
} | ||
|
||
function _execute( | ||
bytes32 method, | ||
bytes memory params | ||
) internal override(GatewayV1Call, PassportV1) { | ||
PassportV1._execute(method, params); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,117 @@ | ||
import { ethers, upgrades } from 'hardhat'; | ||
import { expect } from 'chai'; | ||
import { loadFixture } from 'ethereum-waffle'; | ||
|
||
import { expectBalances } from './utils'; | ||
|
||
const CALL_NETWORK = ethers.utils.keccak256(ethers.utils.toUtf8Bytes('development')); | ||
|
||
describe('PassportAsync', () => { | ||
async function deployFixture() { | ||
const signers = await ethers.getSigners(); | ||
|
||
const BaseV1 = await ethers.getContractFactory('BaseV1'); | ||
const baseV1 = await upgrades.deployProxy(BaseV1, [ | ||
ethers.constants.AddressZero, | ||
ethers.constants.AddressZero, | ||
[], | ||
ethers.constants.AddressZero, | ||
CALL_NETWORK, | ||
1, | ||
]); | ||
|
||
const PassportV1Call = await ethers.getContractFactory('PassportV1AsyncMock'); | ||
const passportV1Call = await upgrades.deployProxy(PassportV1Call, [ | ||
baseV1.address, | ||
'Passport', | ||
'PSP', | ||
ethers.utils.parseEther('1'), | ||
ethers.constants.AddressZero, | ||
ethers.constants.AddressZero, | ||
signers[0].address, | ||
ethers.constants.AddressZero | ||
]); | ||
|
||
await baseV1.setCallAddress(passportV1Call.address); | ||
|
||
const CrowdfundV1 = await ethers.getContractFactory('CrowdfundV1'); | ||
const crowdfundV1 = await upgrades.deployProxy(CrowdfundV1, [passportV1Call.address]); | ||
|
||
return { signers, baseV1, passportV1Call, crowdfundV1 }; | ||
} | ||
|
||
describe('PassportV1', () => { | ||
describe('signer 0', () => { | ||
it('should reserve and refund without supply', async () => { | ||
const { signers, passportV1Call } = await loadFixture(deployFixture); | ||
|
||
const verify = await expectBalances(signers[0].address); | ||
|
||
const [roundIds, price] = await passportV1Call.price(); | ||
|
||
const tx = await passportV1Call.connect(signers[0]).reserve(roundIds, [[signers[0].address, 2]], [], { value: price.mul(2) }); | ||
|
||
await expect(tx) | ||
.to.emit(passportV1Call, 'ExecuteReserve').withNamedArgs({ success: false }); | ||
|
||
const receipt = await tx.wait(); | ||
|
||
await verify( | ||
(n) => n.sub(receipt.gasUsed.mul(receipt.effectiveGasPrice)), | ||
); | ||
}); | ||
}); | ||
}); | ||
|
||
describe('CrowdloanV1', () => { | ||
describe('signer 0', () => { | ||
it('should create', async () => { | ||
const { signers, crowdfundV1 } = await loadFixture(deployFixture); | ||
|
||
await expect(crowdfundV1.connect(signers[0]).create('title', 'description', [[signers[0].address, 2]])) | ||
.to.emit(crowdfundV1, 'Create').withNamedArgs({ campaignId: 1 }); | ||
}); | ||
}); | ||
|
||
describe('signer 1', () => { | ||
it('should fund', async () => { | ||
const { signers, passportV1Call, crowdfundV1 } = await loadFixture(deployFixture); | ||
|
||
const [_, value] = await passportV1Call.price(); | ||
|
||
await expect(crowdfundV1.connect(signers[1]).fund(1, { value })) | ||
.to.emit(crowdfundV1, 'Fund'); | ||
}); | ||
}); | ||
|
||
describe('signer 2', () => { | ||
it('should fund', async () => { | ||
const { signers, passportV1Call, crowdfundV1 } = await loadFixture(deployFixture); | ||
|
||
const [_, value] = await passportV1Call.price(); | ||
|
||
await expect(crowdfundV1.connect(signers[2]).fund(1, { value })) | ||
.to.emit(crowdfundV1, 'Fund'); | ||
}); | ||
}); | ||
|
||
describe('signer 3', () => { | ||
it('should execute and refund without supply', async () => { | ||
const { signers, passportV1Call, crowdfundV1 } = await loadFixture(deployFixture); | ||
|
||
const verify = await expectBalances(signers[1].address, signers[2].address); | ||
|
||
const [roundIds, amount] = await crowdfundV1.goal(1); | ||
|
||
await expect(crowdfundV1.connect(signers[3]).execute(1, roundIds)) | ||
.to.emit(passportV1Call, 'ExecuteReserve').withNamedArgs({ success: false }) | ||
.to.emit(crowdfundV1, 'Execute'); | ||
|
||
await verify( | ||
(n) => n.add(amount.div(2)), | ||
(n) => n.add(amount.div(2)), | ||
); | ||
}); | ||
}); | ||
}); | ||
}); |