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

chore(smart-contracts): cleanup tests from remains of Truffle #13365

Merged
merged 38 commits into from Mar 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
e92040f
refactor hook tests
clemsos Feb 22, 2024
c228074
some more hooks
clemsos Feb 22, 2024
41cc8e6
udt tests
clemsos Feb 22, 2024
bfdd217
add note to clean that up
clemsos Feb 22, 2024
95269b9
fix some more tests
clemsos Feb 22, 2024
f8cc399
more fixes
clemsos Feb 22, 2024
9f5bf00
parse multiple signatures correctly
clemsos Feb 23, 2024
3b5e6f0
remove truffle fixture from main deployment task
clemsos Feb 23, 2024
fc364af
all deployed locks are ethers
clemsos Feb 23, 2024
12af8f4
all deployed ERC20 are ethers
clemsos Feb 23, 2024
7310d93
refactor behaviors tests
clemsos Feb 23, 2024
c558649
fix erc721 tests
clemsos Feb 23, 2024
8ece691
remove BigNumber.js balance helper
clemsos Feb 23, 2024
d9f6d84
fix some more balance helpers
clemsos Feb 23, 2024
31e905d
deploy all locks using truffle by default
clemsos Feb 23, 2024
c862009
some more changes in Unlock tests
clemsos Feb 23, 2024
e3c85cd
refactor gas tests
clemsos Feb 23, 2024
f4baf56
keyManager tests
clemsos Feb 23, 2024
4fe0409
fix all permissions scripts
clemsos Feb 23, 2024
bf03f4e
cleanup some mroe
clemsos Feb 23, 2024
c005713
fix a bunch more
clemsos Feb 28, 2024
2bc973a
fix more tests
clemsos Feb 28, 2024
af2ed4e
fix tests again
clemsos Feb 28, 2024
a5633d6
behaviors fixes
clemsos Mar 1, 2024
0a324cd
skip grant tokens test by default
clemsos Mar 1, 2024
fef43ba
use qualified path
clemsos Mar 1, 2024
885a69c
skip grant tokens test entirely
clemsos Mar 1, 2024
ac85915
fix tokenURI test
clemsos Mar 1, 2024
fb48db9
actually no need to skip
clemsos Mar 1, 2024
b70e8a5
remove truffle from hardhat config - replace all `contract(` by `desc…
clemsos Mar 1, 2024
74a5ee8
remove outdated OZ test helpers
clemsos Mar 5, 2024
d0aa745
fix remaining artifacts/accounts patterns
clemsos Mar 4, 2024
4d2e90e
literal import of `assert`
clemsos Mar 4, 2024
18e5c6c
bunch of fixes
clemsos Mar 4, 2024
2b1a214
cleanup package.json
clemsos Mar 4, 2024
cf3f74f
one last test
clemsos Mar 4, 2024
b2e392e
delete unsued file
clemsos Mar 4, 2024
acf8b21
skip grant tokens on coverage (missing baseFee)
clemsos Mar 4, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 0 additions & 4 deletions smart-contracts/.eslintrc.js
Expand Up @@ -20,13 +20,9 @@ module.exports = {
extends: ['@unlock-protocol/eslint-config'],
globals: {
it: true,
artifacts: true,
contract: true,
describe: true,
before: true,
beforeEach: true,
web3: true,
assert: true,
abi: true,
after: true,
afterEach: true,
Expand Down
14 changes: 7 additions & 7 deletions smart-contracts/contracts/interfaces/IPublicLock.sol
Expand Up @@ -464,6 +464,13 @@ interface IPublicLock {
*/
function safeTransferFrom(address from, address to, uint256 tokenId) external;

function safeTransferFrom(
address from,
address to,
uint256 tokenId,
bytes calldata data
) external;

/**
* an ERC721-like function to transfer a token from one account to another.
* @param from the owner of token to transfer
Expand Down Expand Up @@ -527,13 +534,6 @@ interface IPublicLock {
address _operator
) external view returns (bool);

function safeTransferFrom(
address from,
address to,
uint256 tokenId,
bytes calldata data
) external;

/**
* Returns the total number of keys, including non-valid ones
* @return _totalKeysCreated the total number of keys, valid or not
Expand Down
1 change: 0 additions & 1 deletion smart-contracts/hardhat.config.js
Expand Up @@ -6,7 +6,6 @@ const {
} = require('@unlock-protocol/hardhat-helpers')

require('@nomiclabs/hardhat-ethers')
require('@nomiclabs/hardhat-truffle5')

// full stack trace if needed
require('hardhat-tracer')
Expand Down
13 changes: 1 addition & 12 deletions smart-contracts/package.json
Expand Up @@ -11,13 +11,10 @@
"@connext/interfaces": "2.0.5",
"@nomiclabs/hardhat-ethers": "2.2.3",
"@nomiclabs/hardhat-etherscan": "3.1.8",
"@nomiclabs/hardhat-truffle5": "2.0.7",
"@nomiclabs/hardhat-waffle": "2.0.6",
"@nomiclabs/hardhat-web3": "2.0.0",
"@openzeppelin/contracts": "4.9.5",
"@openzeppelin/contracts-upgradeable": "4.9.5",
"@openzeppelin/hardhat-upgrades": "1.28.0",
"@openzeppelin/test-helpers": "0.5.16",
"@openzeppelin/upgrades-core": "1.27.3",
"@safe-global/safe-core-sdk": "3.3.5",
"@safe-global/safe-ethers-lib": "1.9.3",
Expand All @@ -33,11 +30,9 @@
"@unlock-protocol/networks": "workspace:./packages/networks",
"babel-polyfill": "6.26.0",
"babel-register": "6.26.0",
"bignumber.js": "9.1.2",
"debug": "4.3.4",
"chai": "4.3.10",
"eslint": "8.46.0",
"eth-gas-reporter": "0.2.27",
"eth-sig-util": "3.0.1",
"ethers": "5.7.2",
"fs-extra": "11.1.1",
"hardhat": "2.20.1",
Expand All @@ -46,18 +41,12 @@
"hardhat-gas-reporter": "1.0.10",
"hardhat-storage-layout": "0.1.7",
"hardhat-tracer": "2.8.0",
"hardlydifficult-eth": "1.1.4",
"hardlydifficult-ethereum-contracts": "0.11.1",
"prettier": "3.0.0",
"prettier-plugin-solidity": "1.1.3",
"prompt": "1.3.0",
"solhint": "4.0.0",
"solidity-coverage": "0.8.6",
"yesno": "0.4.0"
},
"devDependencies": {
"chai": "4.3.10"
},
"scripts": {
"test": "hardhat test",
"clean": "rm -rf artifacts",
Expand Down
2 changes: 1 addition & 1 deletion smart-contracts/test/CardPurchaser/purchase.mainnet.js
Expand Up @@ -106,7 +106,7 @@ const signLockPurchase = async ({
return { signature, message, domain, types }
}

describe(`purchase`, function () {
describe(`CardPurchaser / purchase (mainnet only)`, function () {
let chainId, unlock, cardPurchaser, signer, lock, unlockAddress
before(async function () {
if (!process.env.RUN_FORK) {
Expand Down
29 changes: 15 additions & 14 deletions smart-contracts/test/KeyManager/lockmsiths.js
Expand Up @@ -3,48 +3,49 @@ const { setup } = require('./setup')
const { ethers } = require('hardhat')
const { reverts } = require('../helpers')

let keyManager
let keyManager, someAccount

contract('KeyManager / locksmiths', (accounts) => {
describe('KeyManager / locksmiths', () => {
beforeEach(async () => {
;[, , , { address: someAccount }] = await ethers.getSigners()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we don't really care what that is maybe we can rather just create a random one?

;[keyManager] = await setup()
})

it('should let the owner add signer', async () => {
expect(await keyManager.locksmiths(accounts[1])).to.equal(false)
await keyManager.addLocksmith(accounts[1])
expect(await keyManager.locksmiths(accounts[1])).to.equal(true)
expect(await keyManager.locksmiths(someAccount)).to.equal(false)
await keyManager.addLocksmith(someAccount)
expect(await keyManager.locksmiths(someAccount)).to.equal(true)
})

it('should not let someone who is not owner add a signer', async () => {
const [, newOwner] = await ethers.getSigners()
expect(await keyManager.locksmiths(accounts[1])).to.equal(false)
expect(await keyManager.locksmiths(someAccount)).to.equal(false)

await reverts(
keyManager.connect(newOwner).addLocksmith(newOwner.address),
`Ownable: caller is not the owner`
)

expect(await keyManager.locksmiths(accounts[1])).to.equal(false)
expect(await keyManager.locksmiths(someAccount)).to.equal(false)
})

it('should let the owner remove signer', async () => {
await keyManager.addLocksmith(accounts[1])
expect(await keyManager.locksmiths(accounts[1])).to.equal(true)
await keyManager.removeLocksmith(accounts[1])
expect(await keyManager.locksmiths(accounts[1])).to.equal(false)
await keyManager.addLocksmith(someAccount)
expect(await keyManager.locksmiths(someAccount)).to.equal(true)
await keyManager.removeLocksmith(someAccount)
expect(await keyManager.locksmiths(someAccount)).to.equal(false)
})

it('should not let someone who is not owner remove a signer', async () => {
await keyManager.addLocksmith(accounts[1])
expect(await keyManager.locksmiths(accounts[1])).to.equal(true)
await keyManager.addLocksmith(someAccount)
expect(await keyManager.locksmiths(someAccount)).to.equal(true)

const [, newOwner] = await ethers.getSigners()
await reverts(
keyManager.connect(newOwner).removeLocksmith(newOwner.address),
`Ownable: caller is not the owner`
)

expect(await keyManager.locksmiths(accounts[1])).to.equal(true)
expect(await keyManager.locksmiths(someAccount)).to.equal(true)
})
})
15 changes: 8 additions & 7 deletions smart-contracts/test/KeyManager/owner.js
Expand Up @@ -3,32 +3,33 @@ const { ethers } = require('hardhat')
const { setup } = require('./setup')
const { reverts } = require('../helpers')

let keyManager
let keyManager, keyReceiver, firstAccount

contract('KeyManager / Ownable', (accounts) => {
describe('KeyManager / Ownable', () => {
beforeEach(async () => {
;[firstAccount, keyReceiver] = await ethers.getSigners()
;[keyManager] = await setup()
})

it('should be owned by the owner', async () => {
const owner = await keyManager.owner()
expect(owner).to.equal(accounts[0])
expect(owner).to.equal(firstAccount.address)
})

it('should be transferable by the owner to a new owner', async () => {
await keyManager.transferOwnership(accounts[1])
expect(await keyManager.owner()).to.equal(accounts[1])
await keyManager.transferOwnership(keyReceiver.address)
expect(await keyManager.owner()).to.equal(keyReceiver.address)
})

it('should not be transferable by someone who is not an owner', async () => {
const [, newOwner] = await ethers.getSigners()
expect(await keyManager.owner()).to.equal(accounts[0])
expect(await keyManager.owner()).to.equal(firstAccount.address)

await reverts(
keyManager.connect(newOwner).transferOwnership(newOwner.address),
`Ownable: caller is not the owner`
)

expect(await keyManager.owner()).to.equal(accounts[0])
expect(await keyManager.owner()).to.equal(firstAccount.address)
})
})
34 changes: 20 additions & 14 deletions smart-contracts/test/KeyManager/transfer.js
@@ -1,9 +1,10 @@
const { ethers } = require('hardhat')
const { setup } = require('./setup')
const { reverts } = require('../helpers')
const { assert } = require('chai')

let lock
let keyManager
let keyManager, locksmith, grantee, attacker, realUser
const OneMonthFromNow =
Math.floor(new Date().getTime() / 1000) + 60 * 60 * 24 * 30
const OneDayAgo = Math.floor(new Date().getTime() / 1000) - 60 * 60 * 24
Expand All @@ -18,12 +19,17 @@ const types = {
{ name: 'deadline', type: 'uint256' },
],
}
contract('KeyManager', ([, locksmith, grantee, attacker, realUser]) => {
describe('KeyManager', () => {
beforeEach(async () => {
;[keyManager, lock] = await setup()
;[, locksmith, grantee, attacker, realUser] = await ethers.getSigners()
// Let's now aidrop a key to an address and set the keyManager as... keyManager!
await keyManager.addLocksmith(locksmith)
await lock.grantKeys([grantee], [OneMonthFromNow], [keyManager.address])
await keyManager.addLocksmith(locksmith.address)
await lock.grantKeys(
[grantee.address],
[OneMonthFromNow],
[keyManager.address]
)
const { chainId } = await ethers.provider.getNetwork()
domain = {
name: 'KeyManager',
Expand All @@ -37,10 +43,10 @@ contract('KeyManager', ([, locksmith, grantee, attacker, realUser]) => {
const transfer = {
lock: lock.address,
token: 1,
owner: grantee,
owner: grantee.address,
deadline: OneDayAgo,
}
const locksmithSigner = await ethers.getSigner(locksmith)
const locksmithSigner = await ethers.getSigner(locksmith.address)
const signature = await locksmithSigner._signTypedData(
domain,
types,
Expand All @@ -62,10 +68,10 @@ contract('KeyManager', ([, locksmith, grantee, attacker, realUser]) => {
const transfer = {
lock: lock.address,
token: 1,
owner: grantee,
owner: grantee.address,
deadline: OneHourFromNow,
}
const attackerSigner = await ethers.getSigner(attacker)
const attackerSigner = await ethers.getSigner(attacker.address)
const signature = await attackerSigner._signTypedData(
domain,
types,
Expand All @@ -87,21 +93,21 @@ contract('KeyManager', ([, locksmith, grantee, attacker, realUser]) => {
const transfer = {
lock: lock.address,
token: 1,
owner: grantee,
owner: grantee.address,
deadline: OneHourFromNow,
}
assert.notEqual(await lock.ownerOf(1), realUser)
const locksmithSigner = await ethers.getSigner(locksmith)
assert.notEqual(await lock.ownerOf(1), realUser.address)
const locksmithSigner = await ethers.getSigner(locksmith.address)
const signature = await locksmithSigner._signTypedData(
domain,
types,
transfer
)
assert.equal(
ethers.utils.verifyTypedData(domain, types, transfer, signature),
locksmith
locksmith.address
)
const realUserSigner = await ethers.getSigner(realUser)
const realUserSigner = await ethers.getSigner(realUser.address)
await keyManager
.connect(realUserSigner)
.transfer(
Expand All @@ -111,7 +117,7 @@ contract('KeyManager', ([, locksmith, grantee, attacker, realUser]) => {
transfer.deadline,
signature
)
assert.equal(await lock.ownerOf(1), realUser)
assert.equal(await lock.ownerOf(1), realUser.address)
assert.equal(await lock.keyManagerOf(1), keyManager.address)
})
})
4 changes: 2 additions & 2 deletions smart-contracts/test/KeyManager/upgrades.js
Expand Up @@ -4,7 +4,7 @@ const { reverts } = require('../helpers')

let proxy

contract('KeyManager', (accounts) => {
describe('KeyManager', () => {
beforeEach(async () => {
// deploy proxy
const KeyManager = await ethers.getContractFactory('KeyManager')
Expand All @@ -27,7 +27,7 @@ contract('KeyManager', (accounts) => {
})

it('should not be upgradable by an attacker', async () => {
const attacker = await ethers.getSigner(accounts[3])
const [, , , attacker] = await ethers.getSigners()
const KeyManagerV2 = await ethers.getContractFactory(
'KeyManagerV2',
attacker
Expand Down
27 changes: 10 additions & 17 deletions smart-contracts/test/Lock/Lock.js
@@ -1,12 +1,12 @@
const BigNumber = require('bignumber.js')
const { assert } = require('chai')
const { ethers } = require('hardhat')
const { reverts, deployLock } = require('../helpers')
const { reverts, deployLock, compareBigNumbers } = require('../helpers')

const erc777abi = require('@unlock-protocol/hardhat-helpers/dist/ABIs/erc777.json')

let lock

contract('Lock / Lock', (accounts) => {
describe('Lock / Lock', () => {
before(async () => {
lock = await deployLock()
})
Expand All @@ -25,23 +25,16 @@ contract('Lock / Lock', (accounts) => {
lock.totalSupply(),
lock.numberOfOwners(),
])
expirationDuration = new BigNumber(expirationDuration)
maxNumberOfKeys = new BigNumber(maxNumberOfKeys)
totalSupply = new BigNumber(totalSupply)
numberOfOwners = new BigNumber(numberOfOwners)
assert.equal(expirationDuration.toFixed(), 60 * 60 * 24 * 30)
assert.strictEqual(
ethers.utils.formatUnits(ethers.BigNumber.from(keyPrice.toString())),
'0.01'
)
assert.equal(maxNumberOfKeys.toFixed(), 10)
assert.equal(totalSupply.toFixed(), 0)
assert.equal(numberOfOwners.toFixed(), 0)
compareBigNumbers(expirationDuration, 60 * 60 * 24 * 30)
assert.strictEqual(ethers.utils.formatUnits(keyPrice.toString()), '0.01')
compareBigNumbers(maxNumberOfKeys, 10)
compareBigNumbers(totalSupply, 0)
compareBigNumbers(numberOfOwners, 0)
})

it('Should fail on unknown calls', async () => {
const [, recipient] = accounts
const [, recipient] = await ethers.getSigners()
const mock777 = await ethers.getContractAt(erc777abi, lock.address)
await reverts(mock777.send(recipient, 1, '0x'))
await reverts(mock777.send(recipient.address, 1, '0x'))
})
})
1 change: 1 addition & 0 deletions smart-contracts/test/Lock/behaviors/directTips.js
@@ -1,3 +1,4 @@
const { assert } = require('chai')
const { ethers } = require('hardhat')
const { ADDRESS_ZERO } = require('../../helpers')
const { getBalance } = require('../../helpers')
Expand Down