Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
5 changes: 4 additions & 1 deletion smart-contract-extensions/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,7 @@ mnemonic.*
.openzeppelin/.session
.openzeppelin/dev-*
coverage.json
coverage/
coverage/

artifacts
cache
32 changes: 32 additions & 0 deletions smart-contract-extensions/hardhat.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/**
* @type import('hardhat/config').HardhatUserConfig
*/

// gas reporting for tests
require('hardhat-gas-reporter')

// truffle testing
require('@nomiclabs/hardhat-truffle5')

// code coverage
require("solidity-coverage");

const settings = {
optimizer: {
enabled: true,
runs: 2000000,
},
}

module.exports = {
solidity: {
compilers: [
{ version: '0.6.11', settings },
]
},
gasReporter: {
currency: 'USD',
excludeContracts: ['Migrations'],
gasPrice: 5,
},
}
18 changes: 9 additions & 9 deletions smart-contract-extensions/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,11 @@
"description": "Contracts which interact with other contracts",
"scripts": {
"build": "yarn compile",
"compile": "truffle compile",
"test": "truffle test",
"compile": "hardhat compile",
"test": "hardhat test",
"lint": "solium -d ./contracts/ && eslint .",
"lintFix": "solium -d ./contracts/ --fix && eslint . --fix",
"coverage": "truffle run coverage",
"ganache": "ganache-cli",
"coverage": "hardhat coverage",
"ci": "yarn build && yarn test && yarn coverage"
},
"files": [
Expand All @@ -31,29 +30,30 @@
"author": "HardlyDifficult",
"license": "MIT",
"dependencies": {
"@nomiclabs/hardhat-truffle5": "2.0.0",
"@nomiclabs/hardhat-web3": "2.0.0",
"@openzeppelin/contracts": "3.1.0",
"@openzeppelin/test-helpers": "0.5.13",
"@openzeppelin/upgrades": "2.8.0",
"@typescript-eslint/eslint-plugin": "4.3.0",
"@typescript-eslint/parser": "4.3.0",
"@unlock-protocol/unlock-abi-7": "1.0.3",
"@vue/cli": "4.5.13",
"babel-eslint": "10.1.0",
"bignumber.js": "9.0.1",
"chai": "4.2.0",
"coveralls": "3.1.1",
"eslint": "7.8.1",
"eslint-config-prettier": "8.3.0",
"eslint-plugin-json": "3.0.0",
"eslint-plugin-markdown": "2.0.0",
"eslint-plugin-prettier": "3.1.4",
"eth-gas-reporter": "0.2.22",
"hardhat": "^2.6.2",
"hardhat-gas-reporter": "^1.0.4",
"hardlydifficult-eth": "1.1.2",
"prettier": "2.1.1",
"solidity-coverage": "0.7.17",
"solium": "1.2.5",
"truffle": "5.1.43",
"truffle-assertions": "0.9.2",
"truffle-flattener": "1.4.4"
"web3": "1.5.2",
"web3-eth-abi": "^1.5.2"
}
}
20 changes: 12 additions & 8 deletions smart-contract-extensions/test/hooks/codeRequiredHook.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,15 @@ contract('CodeRequiredHook', accounts => {

// Calculate the code account
const code = 'super secret hard to guess code goes here'
const codePK = web3.eth.abi.encodeParameters(

const codePK = web3.utils.keccak256(
web3.eth.abi.encodeParameters(
['address', 'bytes32'],
// By including the lock address in the codePK, we can have
// codes reused for multiple locks without that being visible on-chain
[lock.address, web3.utils.keccak256(code)]
)
))

codeAccount = web3.eth.accounts.privateKeyToAccount(codePK)

// Create the hook contract with that code
Expand Down Expand Up @@ -90,12 +93,13 @@ contract('CodeRequiredHook', accounts => {
it('can not buy with an incorrect code provided', async () => {
// Calculate an incorrect code
const code = 'WRONG'
const codePK = web3.eth.abi.encodeParameters(
['address', 'bytes32'],
// By including the lock address in the codePK, we can have
// codes reused for multiple locks without that being visible on-chain
[lock.address, web3.utils.keccak256(code)]
)
const codePK = web3.utils.keccak256(
web3.eth.abi.encodeParameters(
['address', 'bytes32'],
// By including the lock address in the codePK, we can have
// codes reused for multiple locks without that being visible on-chain
[lock.address, web3.utils.keccak256(code)]
))
const wrongcodeAccount = web3.eth.accounts.privateKeyToAccount(codePK)
const messageToSign = web3.utils.keccak256(
web3.eth.abi.encodeParameters(['address'], [keyBuyer])
Expand Down
2 changes: 1 addition & 1 deletion smart-contract-extensions/test/hooks/discountCodeHook.js
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ contract('DiscountCodeHook', accounts => {
from: keyBuyer,
}
),
'ONLY_LOCK_MANAGER.'
"VM Exception while processing transaction: reverted with reason string 'ONLY_LOCK_MANAGER'"
Copy link
Member Author

Choose a reason for hiding this comment

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

one thing I dont get here is why this was throwing, when others reverts test were not, such as

await reverts(
keyPurchaser.readyToPurchaseFor(endUser, constants.ZERO_ADDRESS, []),
'INSUFFICIENT_ALLOWANCE'
)
await reverts(
keyPurchaser.purchaseFor(endUser, constants.ZERO_ADDRESS, [], {
from: otherAccount,
})
)

Copy link
Member

Choose a reason for hiding this comment

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

Oh well.

)
})

Expand Down
8 changes: 7 additions & 1 deletion smart-contract-extensions/test/uniswapAndCall.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,16 @@ async function createAndFundExchange(uniswap, token, tokenOwner) {
await token.mint(tokenOwner, '1000000000000000000000000', {
from: tokenOwner,
})

await token.approve(exchange.address, -1, { from: tokenOwner })

const blockNumber = await web3.eth.getBlockNumber()
const latestBlock = await web3.eth.getBlock(blockNumber)

await exchange.addLiquidity(
'1',
'1000000000000000000000000',
Math.round(Date.now() / 1000) + 60,
latestBlock.timestamp + 60,
{
from: tokenOwner,
value: web3.utils.toWei('1', 'ether'),
Expand Down Expand Up @@ -139,6 +144,7 @@ contract('swapAndCall', accounts => {
})
})


describe('started with sourceTokens', () => {
beforeEach(async () => {
await sourceToken.mint(testAccount, '1000000000000000000000000', {
Expand Down
33 changes: 0 additions & 33 deletions smart-contract-extensions/truffle-config.js

This file was deleted.

Loading