Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update coverage of test #14326

Open
wants to merge 95 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 79 commits
Commits
Show all changes
95 commits
Select commit Hold shift + click to select a range
8161e68
feat: Add tests for removing locks in Unlock contract
deepsea514 Jul 23, 2024
99d60d8
feat: Add tests for removing locks in Unlock contract
deepsea514 Jul 24, 2024
afd4a03
feat: Add tests for purchasing locks with unlock
deepsea514 Jul 24, 2024
78cf98b
chore: Add test for wrong recipients count in purchaseMultiple.js
deepsea514 Jul 24, 2024
1d581b4
make test for hooks
deepsea514 Jul 29, 2024
aa0361e
update coverage for up
deepsea514 Jul 29, 2024
bc287a6
Merge branch 'master' into master
deepsea514 Jul 29, 2024
ed6cd1c
Merge branch 'master' into master
deepsea514 Jul 30, 2024
d381fe9
Merge branch 'master' into master
deepsea514 Jul 31, 2024
11079ff
Merge branch 'master' into master
julien51 Aug 5, 2024
807d20b
Merge branch 'master' into master
deepsea514 Aug 6, 2024
b5206bc
Merge branch 'unlock-protocol:master' into master
deepsea514 Aug 6, 2024
486e4c4
Merge branch 'master' into master
deepsea514 Aug 8, 2024
18430bc
Merge branch 'master' into master
deepsea514 Aug 13, 2024
8d25ed9
change test case names
deepsea514 Aug 13, 2024
ba0d61b
add test for native token transfer
deepsea514 Aug 13, 2024
4929d7f
Merge branch 'master' into master
clemsos Aug 14, 2024
7fc645e
Merge branch 'master' into master
deepsea514 Aug 14, 2024
cca3dc8
Merge branch 'master' into master
deepsea514 Aug 15, 2024
d23a2d3
Merge branch 'master' into master
deepsea514 Aug 19, 2024
aebd8c8
Merge branch 'master' into master
deepsea514 Aug 19, 2024
fdbbb98
Merge branch 'unlock-protocol:master' into master
deepsea514 Aug 20, 2024
d0aa2cf
ignore CardPurchaser.sol coverage
deepsea514 Aug 20, 2024
5656043
Merge branch 'master' into master
deepsea514 Aug 20, 2024
ecb7ac7
Merge branch 'master' of https://github.com/deepsea514/unlock-protocol
deepsea514 Aug 20, 2024
4bca82b
Merge branch 'master' into master
deepsea514 Aug 21, 2024
0a83e33
Merge branch 'master' into master
deepsea514 Aug 22, 2024
4bc6a4c
Merge branch 'master' into master
deepsea514 Aug 22, 2024
19456f3
chore: Add test case for expired key in transferFee test
deepsea514 Aug 22, 2024
756468b
Merge branch 'master' into master
deepsea514 Aug 22, 2024
2af91f9
set mixinsTransfer coverage into 100%
deepsea514 Aug 22, 2024
7ca6e3a
Merge branch 'master' of https://github.com/deepsea514/unlock-protocol
deepsea514 Aug 22, 2024
3a0fda5
Merge branch 'master' into master
julien51 Aug 22, 2024
651b52a
check updateSchemaVersion in mixinKyes
deepsea514 Aug 22, 2024
5cafb07
Merge branch 'master' of https://github.com/deepsea514/unlock-protocol
deepsea514 Aug 22, 2024
3aeaecf
fix test error for schemaUpdate
deepsea514 Aug 23, 2024
83e2a75
add test for transferring NFT exception.
deepsea514 Aug 26, 2024
2efcac6
Merge branch 'master' into master
deepsea514 Aug 26, 2024
dbc735d
make test for migration required
deepsea514 Aug 27, 2024
89a4a39
make test for invalid erc721 receiver
deepsea514 Aug 27, 2024
4c40bdf
Merge branch 'master' into master
deepsea514 Aug 27, 2024
196c24d
remove failing test using old unlock versions
deepsea514 Aug 27, 2024
09585f8
Merge branch 'master' into master
deepsea514 Aug 29, 2024
f5e8dd6
add test for computeAvailableDiscountFor in unlock
deepsea514 Aug 30, 2024
c340da9
make cancel test for up governor
deepsea514 Aug 30, 2024
ac56003
make test for failed upswap
deepsea514 Aug 30, 2024
bde7ff2
make test for unlock discount token transfer
deepsea514 Aug 30, 2024
d4136f1
make test for UDT governer
deepsea514 Aug 30, 2024
924b35d
make coverage full for governor
deepsea514 Sep 2, 2024
3592e37
Merge branch 'master' into master
deepsea514 Sep 2, 2024
8da21f6
remove console
deepsea514 Sep 2, 2024
e4b23ea
Merge branch 'master' of https://github.com/deepsea514/unlock-protocol
deepsea514 Sep 2, 2024
f3910e6
make test to run with fork mainnet
deepsea514 Sep 3, 2024
f1f2c42
Merge branch 'master' into master
deepsea514 Sep 3, 2024
abad643
restore settings for uniswap oracle test
deepsea514 Sep 3, 2024
8839758
Merge branch 'master' into master
deepsea514 Sep 3, 2024
886f887
skip test for unlockOracle on hardhat test
deepsea514 Sep 3, 2024
5393536
fix test for uniswapOracle mainnet
deepsea514 Sep 3, 2024
94b3e15
add test for cardpurchaser withdraw
deepsea514 Sep 3, 2024
d36a60a
update error name for ownable
deepsea514 Sep 3, 2024
2d19424
check test for uniswapValue.mainnet
deepsea514 Sep 3, 2024
55073c9
skip fork tests
deepsea514 Sep 3, 2024
3d71534
Merge branch 'master' into master
deepsea514 Sep 3, 2024
55a1266
Merge branch 'master' of https://github.com/deepsea514/unlock-protocol
deepsea514 Sep 3, 2024
78d9a50
check failed case for cardpurchase eth transfer
deepsea514 Sep 4, 2024
f865ad1
update skip
deepsea514 Sep 4, 2024
a74fe43
skip old tests
deepsea514 Sep 4, 2024
1d8b58c
Merge branch 'master' into master
deepsea514 Sep 4, 2024
553c7ff
Merge branch 'master' into master
deepsea514 Sep 4, 2024
c1a59c8
add test for proxyAdmin
deepsea514 Sep 4, 2024
b780eec
Merge branch 'master' of https://github.com/deepsea514/unlock-protocol
deepsea514 Sep 4, 2024
ae47be3
Merge branch 'master' of https://github.com/deepsea514/unlock-protocol
deepsea514 Sep 12, 2024
2af0a60
fix error in transfer test
deepsea514 Sep 12, 2024
2dc0433
add some tokens before deploy Lock
deepsea514 Sep 12, 2024
3ed4a5f
Merge branch 'master' into master
deepsea514 Sep 13, 2024
09016f1
fix typo for testerc20
deepsea514 Sep 13, 2024
d46907e
Merge branch 'master' of https://github.com/deepsea514/unlock-protocol
deepsea514 Sep 13, 2024
69d1742
restore comments in migration
deepsea514 Sep 13, 2024
750436c
clean up skip
deepsea514 Sep 13, 2024
a2e2654
Merge branch 'master' into master
deepsea514 Sep 17, 2024
e2a3f40
fix spelling
deepsea514 Sep 17, 2024
f43ae78
remove fork from coverag
deepsea514 Sep 17, 2024
4ac4bef
fix mainnet issue
deepsea514 Sep 17, 2024
7499272
Merge branch 'master' of https://github.com/deepsea514/unlock-protocol
deepsea514 Sep 17, 2024
0b287b9
fix ERC20
deepsea514 Sep 17, 2024
d8ed87e
update solcover
deepsea514 Sep 17, 2024
bf6256c
Merge branch 'master' into master
deepsea514 Sep 18, 2024
f55eb71
Merge branch 'master' into master
deepsea514 Sep 18, 2024
e4ca9cb
Merge branch 'master' into master
deepsea514 Sep 19, 2024
0123c9a
run fork test in only *.mainnet.js
deepsea514 Sep 19, 2024
f7e475c
update coverage script
deepsea514 Sep 19, 2024
e367d90
Merge branch 'master' into master
deepsea514 Sep 20, 2024
f15d430
Merge branch 'master' into master
deepsea514 Sep 20, 2024
edae584
Merge branch 'master' into master
julien51 Sep 24, 2024
3975d43
Merge branch 'master' into master
deepsea514 Sep 30, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion smart-contracts/contracts/mixins/MixinFunds.sol
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ contract MixinFunds is MixinErrors {
function _isValidToken(address _tokenAddress) internal view {
if (
_tokenAddress != address(0) &&
IERC20Upgradeable(_tokenAddress).totalSupply() < 0
IERC20Upgradeable(_tokenAddress).totalSupply() <= 0
deepsea514 marked this conversation as resolved.
Show resolved Hide resolved
) {
revert INVALID_TOKEN();
}
Expand Down
23 changes: 23 additions & 0 deletions smart-contracts/contracts/test-artifacts/TestERC20.sol
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,26 @@ contract TestERC20 is ERC20 {
_mint(holder, amount);
}
}

contract TestERC20WithResultControl is TestERC20 {
bool reuslt;

function setResult(bool _result) public {
reuslt = _result;
deepsea514 marked this conversation as resolved.
Show resolved Hide resolved
}

function transfer(
address recipient,
uint256 amount
) public override returns (bool) {
return reuslt;
}

function transferFrom(
address sender,
address recipient,
uint256 amount
) public override returns (bool) {
return reuslt;
}
}
11 changes: 11 additions & 0 deletions smart-contracts/contracts/test-artifacts/TestERC721Receiver.sol
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,14 @@ contract TestERC721Recevier {
return bytes4(keccak256("onERC721Received(address,address,uint256,bytes)"));
}
}

contract TestERC721RecevierWithWrongResult {
function onERC721Received(
address,
address,
uint256,
bytes calldata
) external returns (bytes4) {
return bytes4(keccak256(""));
}
}
2 changes: 1 addition & 1 deletion smart-contracts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
"lint:code": "eslint .",
"lint": "yarn lint:contracts && yarn lint:code",
"lintFix": "yarn lint:contracts --fix --noPrompt && yarn lint:code --fix",
"coverage": "IS_COVERAGE=1 yarn hardhat coverage",
"coverage": "IS_COVERAGE=1 RUN_FORK=1 yarn hardhat coverage",
deepsea514 marked this conversation as resolved.
Show resolved Hide resolved
"dev": "yarn lint && yarn build && yarn test",
"size": "yarn hardhat size-contracts",
"ci": "yarn lint && yarn test",
Expand Down
81 changes: 66 additions & 15 deletions smart-contracts/test/CardPurchaser/purchase.mainnet.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
const { ethers } = require('hardhat')
const assert = require('assert')
const { deployLock, reverts, ADDRESS_ZERO } = require('../helpers')

const {
deployLock,
getUnlockAddress,
reverts,
addSomeETH,
addSomeUSDC,
} = require('../helpers')

getUnlockAddress,
} = require('@unlock-protocol/hardhat-helpers')
const USDC_ABI = require('@unlock-protocol/hardhat-helpers/dist/ABIs/USDC.json')
const USDC = '0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48'

Expand Down Expand Up @@ -107,15 +105,13 @@ const signLockPurchase = async ({
}

describe(`CardPurchaser / purchase (mainnet only)`, function () {
let chainId, unlock, cardPurchaser, signer, lock, unlockAddress
let chainId, unlock, cardPurchaser, signer, user, lock, unlockAddress
before(async function () {
if (!process.env.RUN_FORK) {
// all suite will be skipped
this.skip()
}
;[signer] = await ethers.getSigners()

await addSomeETH(await signer.getAddress())
;[signer, user] = await ethers.getSigners()

// get Unlock contract
unlockAddress = await getUnlockAddress()
Expand Down Expand Up @@ -205,7 +201,7 @@ describe(`CardPurchaser / purchase (mainnet only)`, function () {
})

it('should fail if the payer is not the sender', async () => {
const notSender = new ethers.Wallet.createRandom()
const notSender = ethers.Wallet.createRandom()
const transfer = await signUSDCTransfer({
chainId,
signer,
Expand All @@ -226,12 +222,12 @@ describe(`CardPurchaser / purchase (mainnet only)`, function () {
purchase.signature,
await purchaseCallData(lock, await signer.getAddress())
),
'PURCHASER_DOES_NOT_MATCH_PAYER()'
'PURCHASER_DOES_NOT_MATCH_PAYER'
)
})

it('should fail if the signature of the purchaseMessage does not match', async () => {
const notSigner = new ethers.Wallet.createRandom()
const notSigner = ethers.Wallet.createRandom()
const transfer = await signUSDCTransfer({
chainId,
signer,
Expand All @@ -253,7 +249,7 @@ describe(`CardPurchaser / purchase (mainnet only)`, function () {
purchase.signature,
await purchaseCallData(lock, await signer.getAddress())
),
'SIGNER_DOES_NOT_MATCH()'
'SIGNER_DOES_NOT_MATCH'
)
})

Expand Down Expand Up @@ -285,7 +281,7 @@ describe(`CardPurchaser / purchase (mainnet only)`, function () {

it('should fail if the transfer of tokens fails because the recipient is not correct!', async () => {
await addSomeUSDC(USDC, await signer.getAddress(), keyPrice)
const notCardPurchaser = new ethers.Wallet.createRandom()
const notCardPurchaser = ethers.Wallet.createRandom()

const transfer = await signUSDCTransfer({
chainId,
Expand Down Expand Up @@ -416,4 +412,59 @@ describe(`CardPurchaser / purchase (mainnet only)`, function () {
0
)
})

describe('withdraw', () => {
it('only owner should be able to withdraw', async () => {
await reverts(
cardPurchaser
.connect(user)
.withdraw(USDC, await signer.getAddress(), 0),
'OwnableUnauthorizedAccount'
)
})

it('owner should be able to withdraw USDC from CardPurchaser', async () => {
const usdcContract = new ethers.Contract(USDC, USDC_ABI, signer)
const balanceBefore = await usdcContract.balanceOf(
await cardPurchaser.getAddress()
)
console.log('balanceBefore =======', balanceBefore)
await cardPurchaser.withdraw(
USDC,
await signer.getAddress(),
balanceBefore
)
assert.equal(
await usdcContract.balanceOf(await cardPurchaser.getAddress()),
0
)
})

it('owner should be able to withdraw ETH from CardPurchaser', async () => {
const balanceBefore = await ethers.provider.getBalance(
await cardPurchaser.getAddress()
)
console.log('balanceBefore =======', balanceBefore)
await cardPurchaser.withdraw(
ADDRESS_ZERO,
await signer.getAddress(),
balanceBefore
)
assert.equal(
await ethers.provider.getBalance(await cardPurchaser.getAddress()),
0
)
})

it('transfer too much ETH from cardpurchaser should fail', async () => {
await reverts(
cardPurchaser.withdraw(
ADDRESS_ZERO,
await signer.getAddress(),
ethers.parseEther('1')
),
'WITHDRAW_FAILED'
)
})
})
})
3 changes: 0 additions & 3 deletions smart-contracts/test/Kickback/kickback.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,6 @@ describe('Kickback contract', () => {
before(async () => {
const [deployer] = await ethers.getSigners()

// deploy unlock
const { unlock } = await deployContracts()

// create a new lock
lock = await deployLock()
const result = await purchaseKeys(lock, 5)
Expand Down
22 changes: 22 additions & 0 deletions smart-contracts/test/Lock/disableTransfers.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,28 @@ describe('Lock / disableTransfers', () => {
await lock.updateTransferFee(10000)
})

it('unauthorized user cannot transfer NFT', async () => {
await reverts(
lock.transferFrom(
await accountWithNoKey.getAddress(),
await accountWithNoKey.getAddress(),
tokenId
),
'UNAUTHORIZED'
)
})

it('transfer NFT to the same address is not allowed', async () => {
await reverts(
lock.transferFrom(
await keyOwner.getAddress(),
await keyOwner.getAddress(),
tokenId
),
'TRANSFER_TO_SELF'
)
})

describe('setting fee to 100%', () => {
describe('disabling transferFrom', () => {
it('should prevent key transfers by reverting', async () => {
Expand Down
18 changes: 18 additions & 0 deletions smart-contracts/test/Lock/erc721/safeTransferFrom.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,24 @@ describe('Lock / erc721 / safeTransferFrom', () => {
assert.equal(ownerOf, await random.getAddress())
})

it('should fail to transfer when a contract implements onERC721Received with Wrong Result', async () => {
;({ tokenId } = await purchaseKey(lock, await random3.getAddress()))
// A contract which does implement onERC721Received:
const TestERC721Recevier = await ethers.getContractFactory(
'TestERC721RecevierWithWrongResult'
)
const nonCompliantContract = await TestERC721Recevier.deploy()

await reverts(
lock
.connect(random3)
[
safeTransferFromSig
](await random3.getAddress(), await nonCompliantContract.getAddress(), tokenId),
'NON_COMPLIANT_ERC721_RECEIVER'
)
})

it('should success to transfer when a contract implements onERC721Received', async () => {
;({ tokenId } = await purchaseKey(lock, await random3.getAddress()))
// A contract which does implement onERC721Received:
Expand Down
4 changes: 4 additions & 0 deletions smart-contracts/test/Lock/erc721/tokenSymbol.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ describe('Lock / erc721 / tokenSymbol', () => {
)
})

it('should return unlockToken Symbol if lock symbol is empty', async () => {
assert.equal(await lock.symbol(), await unlock.globalTokenSymbol())
})

it('should allow the owner to set the global token Symbol', async () => {
assert.equal(await unlock.globalTokenSymbol(), 'KEY')
})
Expand Down
15 changes: 15 additions & 0 deletions smart-contracts/test/Lock/fail.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
const { ethers } = require('hardhat')
const { deployLock, reverts } = require('../helpers')

describe('Lock / fail to deploy', async () => {
it('fail to deploy Lock if invalid ERC20 input', async () => {
const NonToken = await ethers.getContractFactory('TestERC20')
deepsea514 marked this conversation as resolved.
Show resolved Hide resolved
const nonToken = await NonToken.deploy()
await reverts(
deployLock({
tokenAddress: await nonToken.getAddress(),
}),
'INVALID_TOKEN'
)
})
})
5 changes: 5 additions & 0 deletions smart-contracts/test/Lock/grantKeyExtension.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,11 @@ describe('Lock / grantKeyExtension', () => {
;({ tokenId } = args)
})

it('schemaVersion has been updated', async () => {
await lock.updateSchemaVersion()
assert.equal(await lock.schemaVersion(), await lock.publicLockVersion())
})

describe('extend a valid key without a specific duration', () => {
let tsBefore, args
before(async () => {
Expand Down
86 changes: 85 additions & 1 deletion smart-contracts/test/Lock/hooks/CaptchaHook.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,67 @@
const assert = require('assert')
const { ethers } = require('hardhat')
const { reverts, deployLock } = require('../../helpers')
const { reverts, deployLock, ADDRESS_ZERO } = require('../../helpers')

describe('CaptchaHook', function () {
it('random user should not be able to call addSigner and removeSigner', async function () {
const [_, user2] = await ethers.getSigners()
const secretSigner = ethers.Wallet.createRandom()

const CaptchaHook = await ethers.getContractFactory('CaptchaHook')
const hook = await CaptchaHook.deploy()

await reverts(
hook.connect(user2).addSigner(await secretSigner.getAddress()),
'OwnableUnauthorizedAccount'
)
await reverts(
hook.connect(user2).removeSigner(await secretSigner.getAddress()),
'OwnableUnauthorizedAccount'
)
})

it('owner should be able to call addSigner and removeSigner', async function () {
const [_, user2] = await ethers.getSigners()
const secretSigner = ethers.Wallet.createRandom()

const CaptchaHook = await ethers.getContractFactory('CaptchaHook')
const hook = await CaptchaHook.deploy()

await (await hook.addSigner(await secretSigner.getAddress())).wait()
const isSignerBefore = await hook.signers(await secretSigner.getAddress())
assert.equal(isSignerBefore, true)

await (await hook.removeSigner(await secretSigner.getAddress())).wait()
const isSignerAfter = await hook.signers(await secretSigner.getAddress())
assert.equal(isSignerAfter, false)
})

it('keyPurchasePrice should be 0 if caller is not a contract', async () => {
const secretSigner = ethers.Wallet.createRandom()
const [user] = await ethers.getSigners()

const CaptchaHook = await ethers.getContractFactory('CaptchaHook')
const hook = await CaptchaHook.deploy()
await (await hook.addSigner(await secretSigner.getAddress())).wait()

const messageHash = ethers.solidityPackedKeccak256(
['string'],
[(await user.getAddress()).toLowerCase()]
)
const signedMessage = await secretSigner.signMessage(
ethers.getBytes(messageHash)
)

const price = await hook.keyPurchasePrice(
await user.getAddress(),
await user.getAddress(),
await user.getAddress(),
signedMessage
)

assert.equal(price, 0)
})

it('Should work', async function () {
const [user] = await ethers.getSigners()
const secretSigner = ethers.Wallet.createRandom()
Expand Down Expand Up @@ -125,4 +184,29 @@ describe('CaptchaHook', function () {
'ECDSAInvalidSignatureLength'
)
})

it('toString - number', async () => {
const CaptchaHook = await ethers.getContractFactory('CaptchaHook')
const hook = await CaptchaHook.deploy()

const toStringFunction = hook.getFunction(
'function toString(uint256) public pure returns (string memory)'
)
const value = 123
const result = await toStringFunction(value)
assert.equal(result.includes(value.toString(16)), true)
})

it('toString - string', async () => {
const CaptchaHook = await ethers.getContractFactory('CaptchaHook')
const hook = await CaptchaHook.deploy()

const value = `0x${ethers.parseEther('10').toString(16)}`
const hexString = ethers.hexlify(ethers.zeroPadValue(value, 32))
const toStringFunction = hook.getFunction(
'function toString(bytes32) public pure returns (string memory)'
)
const result = await toStringFunction(hexString)
assert.equal(result, hexString)
})
})
Loading
Loading