Skip to content

Commit

Permalink
Delegate tests coverage (#1326)
Browse files Browse the repository at this point in the history
* Scripts enhancements (#1321)

* Added checks to validate target deployment address matches mainnet

* Added storing of commit hashes upon deployment to track deployed code

* Created script to populate the latest deploy commits

* Renamed deploy commits script for clarity

* Updated module declarations

* Removed script to populate hashes

* prompt language update

---------

Co-authored-by: Don Mosites <[email protected]>

* Bump micromatch from 4.0.5 to 4.0.8 (#1323)

Bumps [micromatch](https://github.com/micromatch/micromatch) from 4.0.5 to 4.0.8.
- [Release notes](https://github.com/micromatch/micromatch/releases)
- [Changelog](https://github.com/micromatch/micromatch/blob/master/CHANGELOG.md)
- [Commits](micromatch/micromatch@4.0.5...4.0.8)

---
updated-dependencies:
- dependency-name: micromatch
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* Bump axios from 1.6.7 to 1.7.7 (#1324)

Bumps [axios](https://github.com/axios/axios) from 1.6.7 to 1.7.7.
- [Release notes](https://github.com/axios/axios/releases)
- [Changelog](https://github.com/axios/axios/blob/v1.x/CHANGELOG.md)
- [Commits](axios/axios@v1.6.7...v1.7.7)

---
updated-dependencies:
- dependency-name: axios
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* Increased Delegate test coverage to 100%

---------

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: Don Mosites <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
  • Loading branch information
3 people authored Sep 4, 2024
1 parent cf58ace commit b8243ac
Show file tree
Hide file tree
Showing 29 changed files with 409 additions and 22 deletions.
19 changes: 19 additions & 0 deletions source/batch-call/deploys-commits.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
module.exports = {
1: '863586ae7594b5088619f243dbee83c8d8e0075f',
31: '863586ae7594b5088619f243dbee83c8d8e0075f',
41: '863586ae7594b5088619f243dbee83c8d8e0075f',
56: '863586ae7594b5088619f243dbee83c8d8e0075f',
97: '863586ae7594b5088619f243dbee83c8d8e0075f',
137: '863586ae7594b5088619f243dbee83c8d8e0075f',
8453: '863586ae7594b5088619f243dbee83c8d8e0075f',
17000: '863586ae7594b5088619f243dbee83c8d8e0075f',
42161: '863586ae7594b5088619f243dbee83c8d8e0075f',
43113: '863586ae7594b5088619f243dbee83c8d8e0075f',
43114: '863586ae7594b5088619f243dbee83c8d8e0075f',
59140: '863586ae7594b5088619f243dbee83c8d8e0075f',
59144: '863586ae7594b5088619f243dbee83c8d8e0075f',
80001: '863586ae7594b5088619f243dbee83c8d8e0075f',
84532: '863586ae7594b5088619f243dbee83c8d8e0075f',
421614: '863586ae7594b5088619f243dbee83c8d8e0075f',
11155111: '863586ae7594b5088619f243dbee83c8d8e0075f',
}
1 change: 1 addition & 0 deletions source/batch-call/deploys-commits.js.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
declare module '@airswap/batch-call/deploys-commits.js'
35 changes: 32 additions & 3 deletions source/batch-call/scripts/deploy.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ const { ChainIds, chainLabels } = require('@airswap/utils')
const { getReceiptUrl } = require('@airswap/utils')
const batchCallDeploys = require('../deploys.js')
const batchCallBlocks = require('../deploys-blocks.js')
const batchCallCommits = require('../deploys-commits.js')
const { displayDeployerInfo } = require('../../../scripts/deployer-info')

async function main() {
Expand All @@ -18,9 +19,13 @@ async function main() {
console.log('Value for --network flag is required')
return
}
await displayDeployerInfo(deployer)

const prompt = new Confirm('Proceed to deploy?')
const targetAddress = await displayDeployerInfo(deployer)
const mainnetAddress = batchCallDeploys['1']
const prompt = new Confirm(
targetAddress === mainnetAddress
? 'Proceed to deploy?'
: 'Contract address would not match current mainnet address. Proceed anyway?'
)
if (await prompt.run()) {
const batchFactory = await ethers.getContractFactory('BatchCall')
const batchCallContract = await batchFactory.deploy()
Expand Down Expand Up @@ -48,6 +53,30 @@ async function main() {
{ ...prettierConfig, parser: 'babel' }
)
)

batchCallBlocks[chainId] = (
await batchCallContract.deployTransaction.wait()
).blockNumber
fs.writeFileSync(
'./deploys-blocks.js',
prettier.format(
`module.exports = ${JSON.stringify(batchCallBlocks, null, '\t')}`,
{ ...prettierConfig, parser: 'babel' }
)
)

batchCallCommits[chainId] = require('child_process')
.execSync('git rev-parse HEAD')
.toString()
.trim()
fs.writeFileSync(
'./deploys-commits.js',
prettier.format(
`module.exports = ${JSON.stringify(batchCallCommits, null, '\t')}`,
{ ...prettierConfig, parser: 'babel' }
)
)

console.log(
`Deployed: ${batchCallDeploys[chainId]} @ ${batchCallBlocks[chainId]}`
)
Expand Down
3 changes: 3 additions & 0 deletions source/delegate/deploys-commits.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = {
11155111: 'da05cb9528630f4f2e15ce3f9093b0f944bec1b7',
}
1 change: 1 addition & 0 deletions source/delegate/deploys-commits.js.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
declare module '@airswap/delegate/deploys-commits.js'
20 changes: 19 additions & 1 deletion source/delegate/scripts/deploy.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ const { ChainIds, chainLabels } = require('@airswap/utils')
const { getReceiptUrl } = require('@airswap/utils')
const delegateDeploys = require('../deploys.js')
const delegateBlocks = require('../deploys-blocks.js')
const delegateCommits = require('../deploys-commits.js')
const { displayDeployerInfo } = require('../../../scripts/deployer-info')

async function main() {
Expand All @@ -23,7 +24,13 @@ async function main() {

console.log(`swapERC20Contract: ${swapERC20Deploys[chainId]}\n`)

const prompt = new Confirm('Proceed to deploy?')
const targetAddress = await displayDeployerInfo(deployer)
const mainnetAddress = delegateDeploys['1']
const prompt = new Confirm(
targetAddress === mainnetAddress
? 'Proceed to deploy?'
: 'Contract address would not match current mainnet address. Proceed anyway?'
)
if (await prompt.run()) {
const delegateFactory = await ethers.getContractFactory('Delegate')
const delegateContract = await delegateFactory.deploy(
Expand Down Expand Up @@ -53,6 +60,17 @@ async function main() {
{ ...prettierConfig, parser: 'babel' }
)
)
delegateCommits[chainId] = require('child_process')
.execSync('git rev-parse HEAD')
.toString()
.trim()
fs.writeFileSync(
'./deploys-commits.js',
prettier.format(
`module.exports = ${JSON.stringify(delegateCommits, null, '\t')}`,
{ ...prettierConfig, parser: 'babel' }
)
)
console.log(
`Deployed: ${delegateDeploys[chainId]} @ ${delegateBlocks[chainId]}`
)
Expand Down
79 changes: 79 additions & 0 deletions source/delegate/test/Delegate.js
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,12 @@ describe('Delegate Unit', () => {
expect(await delegate.swapERC20()).to.equal(UPDATE_SWAP_ERC20_ADDRESS)
})

it('the swapERC20Contract address cannot be address(0)', async () => {
await expect(
delegate.setSwapERC20Contract(ADDRESS_ZERO)
).to.be.revertedWith('InvalidAddress')
})

it('only the owner can set the swapERC20Contract address', async () => {
await expect(
delegate.connect(anyone).setSwapERC20Contract(UPDATE_SWAP_ERC20_ADDRESS)
Expand Down Expand Up @@ -210,6 +216,37 @@ describe('Delegate Unit', () => {
)
})

it('an unauthorized manager cannot set a rule', async () => {
await delegate.connect(sender).authorize(manager.address)
await expect(
delegate
.connect(signer)
.setRule(
sender.address,
senderToken.address,
DEFAULT_SENDER_AMOUNT,
signerToken.address,
DEFAULT_SIGNER_AMOUNT,
RULE_EXPIRY
)
).to.be.revertedWith('SenderInvalid')
})

it('a manager cannot set a rule without prior authorization', async () => {
await expect(
delegate
.connect(manager)
.setRule(
sender.address,
senderToken.address,
DEFAULT_SENDER_AMOUNT,
signerToken.address,
DEFAULT_SIGNER_AMOUNT,
RULE_EXPIRY
)
).to.be.revertedWith('SenderInvalid')
})

it('a manager can unset a Rule', async () => {
await delegate.connect(sender).authorize(manager.address)
await delegate
Expand All @@ -232,6 +269,48 @@ describe('Delegate Unit', () => {
.withArgs(sender.address, senderToken.address, signerToken.address)
})

it('an unauthorized manager cannot unset a rule', async () => {
await delegate.connect(sender).authorize(manager.address)
await delegate
.connect(manager)
.setRule(
sender.address,
senderToken.address,
DEFAULT_SENDER_AMOUNT,
signerToken.address,
DEFAULT_SIGNER_AMOUNT,
RULE_EXPIRY
)

await expect(
delegate
.connect(signer)
.unsetRule(sender.address, senderToken.address, signerToken.address)
).to.be.revertedWith('SenderInvalid')
})

it('a revoked manager cannot unset a rule', async () => {
await delegate.connect(sender).authorize(manager.address)
await delegate
.connect(manager)
.setRule(
sender.address,
senderToken.address,
DEFAULT_SENDER_AMOUNT,
signerToken.address,
DEFAULT_SIGNER_AMOUNT,
RULE_EXPIRY
)

await delegate.connect(sender).revoke()

await expect(
delegate
.connect(manager)
.unsetRule(sender.address, senderToken.address, signerToken.address)
).to.be.revertedWith('SenderInvalid')
})

it('setting a Rule updates the rule balance', async () => {
await delegate
.connect(sender)
Expand Down
22 changes: 22 additions & 0 deletions source/pool/deploys-commits.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
module.exports = {
1: 'a535d0bb280fdb603a903dd2ae94e6b27d66b3d4',
5: 'a535d0bb280fdb603a903dd2ae94e6b27d66b3d4',
30: 'a535d0bb280fdb603a903dd2ae94e6b27d66b3d4',
31: 'a535d0bb280fdb603a903dd2ae94e6b27d66b3d4',
40: 'a535d0bb280fdb603a903dd2ae94e6b27d66b3d4',
41: 'a535d0bb280fdb603a903dd2ae94e6b27d66b3d4',
56: 'a535d0bb280fdb603a903dd2ae94e6b27d66b3d4',
97: 'a535d0bb280fdb603a903dd2ae94e6b27d66b3d4',
137: 'a535d0bb280fdb603a903dd2ae94e6b27d66b3d4',
8453: 'a535d0bb280fdb603a903dd2ae94e6b27d66b3d4',
17000: 'a535d0bb280fdb603a903dd2ae94e6b27d66b3d4',
42161: 'a535d0bb280fdb603a903dd2ae94e6b27d66b3d4',
43113: 'a535d0bb280fdb603a903dd2ae94e6b27d66b3d4',
43114: 'a535d0bb280fdb603a903dd2ae94e6b27d66b3d4',
59140: 'a535d0bb280fdb603a903dd2ae94e6b27d66b3d4',
59144: 'a535d0bb280fdb603a903dd2ae94e6b27d66b3d4',
80001: 'a535d0bb280fdb603a903dd2ae94e6b27d66b3d4',
84531: 'a535d0bb280fdb603a903dd2ae94e6b27d66b3d4',
421613: 'a535d0bb280fdb603a903dd2ae94e6b27d66b3d4',
11155111: 'a535d0bb280fdb603a903dd2ae94e6b27d66b3d4',
}
1 change: 1 addition & 0 deletions source/pool/deploys-commits.js.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
declare module '@airswap/pool/deploys-commits.js'
20 changes: 19 additions & 1 deletion source/pool/scripts/deploy.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ const { chainLabels, ChainIds } = require('@airswap/utils')
const { getReceiptUrl } = require('@airswap/utils')
const poolDeploys = require('../deploys.js')
const poolBlocks = require('../deploys-blocks.js')
const poolCommits = require('../deploys-commits.js')
const { displayDeployerInfo } = require('../../../scripts/deployer-info')

async function main() {
Expand All @@ -26,7 +27,13 @@ async function main() {
console.log(`scale: ${scale}`)
console.log(`max: ${max}`)

const prompt = new Confirm('Proceed to deploy?')
const targetAddress = await displayDeployerInfo(deployer)
const mainnetAddress = poolDeploys['1']
const prompt = new Confirm(
targetAddress === mainnetAddress
? 'Proceed to deploy?'
: 'Contract address would not match current mainnet address. Proceed anyway?'
)
if (await prompt.run()) {
const poolFactory = await ethers.getContractFactory('Pool')
const poolContract = await poolFactory.deploy(scale, max)
Expand Down Expand Up @@ -54,6 +61,17 @@ async function main() {
{ ...prettierConfig, parser: 'babel' }
)
)
poolCommits[chainId] = require('child_process')
.execSync('git rev-parse HEAD')
.toString()
.trim()
fs.writeFileSync(
'./deploys-commits.js',
prettier.format(
`module.exports = ${JSON.stringify(poolCommits, null, '\t')}`,
{ ...prettierConfig, parser: 'babel' }
)
)
console.log(`Deployed: ${poolDeploys[chainId]} @ ${poolBlocks[chainId]}`)

console.log(
Expand Down
19 changes: 19 additions & 0 deletions source/registry/deploys-commits.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
module.exports = {
1: '863586ae7594b5088619f243dbee83c8d8e0075f',
31: '863586ae7594b5088619f243dbee83c8d8e0075f',
41: '863586ae7594b5088619f243dbee83c8d8e0075f',
56: '863586ae7594b5088619f243dbee83c8d8e0075f',
97: '863586ae7594b5088619f243dbee83c8d8e0075f',
137: '863586ae7594b5088619f243dbee83c8d8e0075f',
8453: '863586ae7594b5088619f243dbee83c8d8e0075f',
17000: '863586ae7594b5088619f243dbee83c8d8e0075f',
42161: '863586ae7594b5088619f243dbee83c8d8e0075f',
43113: '863586ae7594b5088619f243dbee83c8d8e0075f',
43114: '863586ae7594b5088619f243dbee83c8d8e0075f',
59140: '863586ae7594b5088619f243dbee83c8d8e0075f',
59144: '863586ae7594b5088619f243dbee83c8d8e0075f',
80001: '863586ae7594b5088619f243dbee83c8d8e0075f',
84532: '863586ae7594b5088619f243dbee83c8d8e0075f',
421614: '863586ae7594b5088619f243dbee83c8d8e0075f',
11155111: '863586ae7594b5088619f243dbee83c8d8e0075f',
}
1 change: 1 addition & 0 deletions source/registry/deploys-commits.js.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
declare module '@airswap/registry/deploys-commits.js'
20 changes: 19 additions & 1 deletion source/registry/scripts/deploy.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ const { ChainIds, chainLabels } = require('@airswap/utils')
const { getReceiptUrl } = require('@airswap/utils')
const registryDeploys = require('../deploys.js')
const registryBlocks = require('../deploys-blocks.js')
const registryCommits = require('../deploys-commits.js')
const config = require('./config.js')
const { displayDeployerInfo } = require('../../../scripts/deployer-info')

Expand Down Expand Up @@ -35,7 +36,13 @@ async function main() {
console.log(`stakingCost: ${stakingCost}`)
console.log(`supportCost: ${supportCost}\n`)

const prompt = new Confirm('Proceed to deploy?')
const targetAddress = await displayDeployerInfo(deployer)
const mainnetAddress = registryDeploys['1']
const prompt = new Confirm(
targetAddress === mainnetAddress
? 'Proceed to deploy?'
: 'Contract address would not match current mainnet address. Proceed anyway?'
)
if (await prompt.run()) {
const registryFactory = await ethers.getContractFactory('Registry')
const registryContract = await registryFactory.deploy(
Expand Down Expand Up @@ -67,6 +74,17 @@ async function main() {
{ ...prettierConfig, parser: 'babel' }
)
)
registryCommits[chainId] = require('child_process')
.execSync('git rev-parse HEAD')
.toString()
.trim()
fs.writeFileSync(
'./deploys-commits.js',
prettier.format(
`module.exports = ${JSON.stringify(registryCommits, null, '\t')}`,
{ ...prettierConfig, parser: 'babel' }
)
)
console.log(
`Deployed: ${registryDeploys[chainId]} @ ${registryBlocks[chainId]}`
)
Expand Down
5 changes: 5 additions & 0 deletions source/staking/deploys-commits.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module.exports = {
1: '6ede424741588b8e3fbb8060cc9ee8d343eac4ab',
17000: '6ede424741588b8e3fbb8060cc9ee8d343eac4ab',
11155111: '6ede424741588b8e3fbb8060cc9ee8d343eac4ab',
}
1 change: 1 addition & 0 deletions source/staking/deploys-commits.js.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
declare module '@airswap/staking/deploys-commits.js'
Loading

0 comments on commit b8243ac

Please sign in to comment.