Skip to content

Commit 80e380c

Browse files
authored
Tests: Avoid hardcoded addresses (#22)
1 parent 4252ae2 commit 80e380c

18 files changed

Lines changed: 97 additions & 97 deletions

File tree

examples/02-simple-transfer-with-inputs/tests/task.spec.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,22 @@
1-
import { fp, OpType } from '@mimicprotocol/sdk'
1+
import { fp, OpType, randomEvmAddress } from '@mimicprotocol/sdk'
22
import { Context, ContractCallMock, runTask, Transfer } from '@mimicprotocol/test-ts'
33
import { expect } from 'chai'
44

55
describe('Task', () => {
66
const taskDir = './build'
77

88
const context: Context = {
9-
user: '0x756f45e3fa69347a9a973a725e3c98bc4db0b5a0',
10-
settlers: [{ address: '0xdcf1d9d12a0488dfb70a8696f44d6d3bc303963d', chainId: 10 }],
9+
user: randomEvmAddress(),
10+
settlers: [{ address: randomEvmAddress(), chainId: 10 }],
1111
timestamp: Date.now(),
1212
}
1313

1414
const inputs = {
1515
chainId: 10, // Optimism
16-
token: '0x7f5c764cbc14f9669b88837ca1490cca17c31607', // USDC
17-
amount: '1.5', // 1.5 USDC
18-
recipient: '0xbce3248ede29116e4bd18416dcc2dfca668eeb84',
19-
maxFee: '0.1', // 0.1 USDC
16+
token: randomEvmAddress(),
17+
amount: '1.5', // 1.5 tokens
18+
recipient: randomEvmAddress(),
19+
maxFee: '0.1', // 0.1 tokens
2020
}
2121

2222
const calls: ContractCallMock[] = [

examples/03-transfer-balance-threshold/tests/task.spec.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,23 @@
1-
import { fp, OpType } from '@mimicprotocol/sdk'
1+
import { fp, OpType, randomEvmAddress } from '@mimicprotocol/sdk'
22
import { Context, ContractCallMock, runTask, Transfer } from '@mimicprotocol/test-ts'
33
import { expect } from 'chai'
44

55
describe('Task', () => {
66
const taskDir = './build'
77

88
const context: Context = {
9-
user: '0x756f45e3fa69347a9a973a725e3c98bc4db0b5a0',
10-
settlers: [{ address: '0xdcf1d9d12a0488dfb70a8696f44d6d3bc303963d', chainId: 10 }],
9+
user: randomEvmAddress(),
10+
settlers: [{ address: randomEvmAddress(), chainId: 10 }],
1111
timestamp: Date.now(),
1212
}
1313

1414
const inputs = {
1515
chainId: 10, // Optimism
16-
token: '0x7f5c764cbc14f9669b88837ca1490cca17c31607', // USDC
17-
amount: '1', // 1 USDC
18-
recipient: '0xbce3248ede29116e4bd18416dcc2dfca668eeb84',
19-
maxFee: '0.1', // 0.1 USDC
20-
threshold: '10.2', // 10.2 USDC
16+
token: randomEvmAddress(),
17+
amount: '1', // 1 token
18+
recipient: randomEvmAddress(),
19+
maxFee: '0.1', // 0.1 tokens
20+
threshold: '10.2', // 10.2 tokens
2121
}
2222

2323
const buildCalls = (balance: string): ContractCallMock[] => [
@@ -52,7 +52,7 @@ describe('Task', () => {
5252
]
5353

5454
describe('when the balance is below the threshold', () => {
55-
const balance = '9000000' // 9 USDC
55+
const balance = '9000000' // 9 tokens
5656
const calls = buildCalls(balance)
5757

5858
it('produces the expected intents', async () => {
@@ -79,7 +79,7 @@ describe('Task', () => {
7979
})
8080

8181
describe('when the balance is above the threshold', () => {
82-
const balance = '11000000' // 11 USDC
82+
const balance = '11000000' // 11 tokens
8383
const calls = buildCalls(balance)
8484

8585
it('does not produce any intent', async () => {

examples/04-transfer-balance-threshold-with-oracles/tests/task.spec.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,22 @@
1-
import { fp, OpType } from '@mimicprotocol/sdk'
1+
import { fp, OpType, randomEvmAddress } from '@mimicprotocol/sdk'
22
import { Context, ContractCallMock, GetPriceMock, runTask, Transfer } from '@mimicprotocol/test-ts'
33
import { expect } from 'chai'
44

55
describe('Task', () => {
66
const taskDir = './build'
77

88
const context: Context = {
9-
user: '0x756f45e3fa69347a9a973a725e3c98bc4db0b5a0',
10-
settlers: [{ address: '0xdcf1d9d12a0488dfb70a8696f44d6d3bc303963d', chainId: 10 }],
9+
user: randomEvmAddress(),
10+
settlers: [{ address: randomEvmAddress(), chainId: 10 }],
1111
timestamp: Date.now(),
1212
}
1313

1414
const inputs = {
1515
chainId: 10, // Optimism
16-
token: '0x7f5c764cbc14f9669b88837ca1490cca17c31607', // USDC
17-
amount: '1', // 1 USDC
18-
recipient: '0xbce3248ede29116e4bd18416dcc2dfca668eeb84',
19-
maxFee: '0.1', // 0.1 USDC
16+
token: randomEvmAddress(),
17+
amount: '1', // 1 token
18+
recipient: randomEvmAddress(),
19+
maxFee: '0.1', // 0.1 tokens
2020
thresholdUsd: '10.5', // 10.5 USD
2121
}
2222

@@ -26,7 +26,7 @@ describe('Task', () => {
2626
token: inputs.token,
2727
chainId: inputs.chainId,
2828
},
29-
response: ['1000000000000000000'], // 1 USD = 1 USDC
29+
response: ['1000000000000000000'], // 1 token = 1 USD
3030
},
3131
]
3232

@@ -62,7 +62,7 @@ describe('Task', () => {
6262
]
6363

6464
describe('when the balance is below the threshold', () => {
65-
const balance = '9000000' // 9 USDC
65+
const balance = '9000000' // 9 tokens
6666
const calls = buildCalls(balance)
6767

6868
it('produces the expected intents', async () => {
@@ -92,7 +92,7 @@ describe('Task', () => {
9292
})
9393

9494
describe('when the balance is above the threshold', () => {
95-
const balance = '11000000' // 11 USDC
95+
const balance = '11000000' // 11 tokens
9696
const calls = buildCalls(balance)
9797

9898
it('does not produce any intent', async () => {

examples/05-invest-aave-idle-balance/tests/task.spec.ts

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { EvmCallIntent, OpType } from '@mimicprotocol/sdk'
1+
import { EvmCallIntent, OpType, randomEvmAddress } from '@mimicprotocol/sdk'
22
import { Context, ContractCallMock, GetPriceMock, runTask } from '@mimicprotocol/test-ts'
33
import { expect } from 'chai'
44
import { Interface } from 'ethers'
@@ -13,36 +13,36 @@ describe('Task', () => {
1313
const taskDir = './build'
1414

1515
const context: Context = {
16-
user: '0x756f45e3fa69347a9a973a725e3c98bc4db0b5a0',
17-
settlers: [{ address: '0xdcf1d9d12a0488dfb70a8696f44d6d3bc303963d', chainId: 10 }],
16+
user: randomEvmAddress(),
17+
settlers: [{ address: randomEvmAddress(), chainId: 10 }],
1818
timestamp: Date.now(),
1919
}
2020

2121
const inputs = {
2222
chainId: 10, // Optimism
23-
aToken: '0x625e7708f30ca75bfd92586e17077590c60eb4cd', // Aave Optimism USDC
24-
smartAccount: '0x756f45e3fa69347a9a973a725e3c98bc4db0b5a1',
23+
aToken: randomEvmAddress(), // Aave Optimism USDC
24+
smartAccount: randomEvmAddress(),
2525
thresholdUsd: '10.5', // 10.5 USD
2626
maxFeeUsd: '0.1', // 0.1 USD
2727
}
2828

29-
const underlyingToken = '0x7f5c764cbc14f9669b88837ca1490cca17c31607' // USDC
30-
const pool = '0x794a61358d6845594f94dc1db02a252b5b4814ad' // Aave Pool
29+
const underlyingToken = randomEvmAddress() // USDC
30+
const aavePool = randomEvmAddress()
3131

3232
const prices: GetPriceMock[] = [
3333
{
3434
request: {
3535
token: inputs.aToken,
3636
chainId: inputs.chainId,
3737
},
38-
response: ['1000000000000000000'], // 1 USD = 1 aOptUSDC
38+
response: ['1000000000000000000'], // 1 aOptUSDC = 1 USD
3939
},
4040
{
4141
request: {
4242
token: underlyingToken,
4343
chainId: inputs.chainId,
4444
},
45-
response: ['1000000000000000000'], // 1 USD = 1 USDC
45+
response: ['1000000000000000000'], // 1 USDC = 1 USD
4646
},
4747
]
4848

@@ -66,7 +66,7 @@ describe('Task', () => {
6666
fnSelector: '0x7535d246', // `POOL`
6767
},
6868
response: {
69-
value: pool,
69+
value: aavePool,
7070
abiType: 'address',
7171
},
7272
},
@@ -166,7 +166,7 @@ describe('Task', () => {
166166
expect(intents[0].user).to.be.equal(inputs.smartAccount)
167167
expect(intents[0].chainId).to.be.equal(inputs.chainId)
168168

169-
const expectedApproveData = ERC20Interface.encodeFunctionData('approve', [pool, balance])
169+
const expectedApproveData = ERC20Interface.encodeFunctionData('approve', [aavePool, balance])
170170
expect(intents[0].calls[0].target).to.be.equal(underlyingToken)
171171
expect(intents[0].calls[0].value).to.be.equal('0')
172172
expect(intents[0].calls[0].data).to.be.equal(expectedApproveData)
@@ -177,7 +177,7 @@ describe('Task', () => {
177177
inputs.smartAccount,
178178
0,
179179
])
180-
expect(intents[0].calls[1].target).to.be.equal(pool)
180+
expect(intents[0].calls[1].target).to.be.equal(aavePool)
181181
expect(intents[0].calls[1].value).to.be.equal('0')
182182
expect(intents[0].calls[1].data).to.be.equal(expectedSupplyData)
183183

examples/06-withdraw-from-aave-balance-threshold/tests/task.spec.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,40 @@
1-
import { OpType } from '@mimicprotocol/sdk'
1+
import { OpType, randomEvmAddress } from '@mimicprotocol/sdk'
22
import { Context, ContractCallMock, GetPriceMock, runTask, Swap } from '@mimicprotocol/test-ts'
33
import { expect } from 'chai'
44

55
describe('Task', () => {
66
const taskDir = './build'
77

88
const context: Context = {
9-
user: '0x756f45e3fa69347a9a973a725e3c98bc4db0b5a0',
10-
settlers: [{ address: '0xdcf1d9d12a0488dfb70a8696f44d6d3bc303963d', chainId: 10 }],
9+
user: randomEvmAddress(),
10+
settlers: [{ address: randomEvmAddress(), chainId: 10 }],
1111
timestamp: Date.now(),
1212
}
1313

1414
const inputs = {
1515
chainId: 10, // Optimism
16-
aToken: '0x625e7708f30ca75bfd92586e17077590c60eb4cd', // Aave Optimism USDC
16+
aToken: randomEvmAddress(), // Aave Optimism USDC
1717
slippageBps: 200, // 2%
1818
thresholdUsd: '10', // 10 USD
19-
recipient: '0xbce3248ede29116e4bd18416dcc2dfca668eeb84',
19+
recipient: randomEvmAddress(),
2020
}
2121

22-
const underlyingToken = '0x7f5c764cbc14f9669b88837ca1490cca17c31607' // USDC
22+
const underlyingToken = randomEvmAddress() // USDC
2323

2424
const prices: GetPriceMock[] = [
2525
{
2626
request: {
2727
token: inputs.aToken,
2828
chainId: inputs.chainId,
2929
},
30-
response: ['1000000000000000000'], // 1 USD = 1 aOptUSDC
30+
response: ['1000000000000000000'], // 1 aOptUSDC = 1 USD
3131
},
3232
{
3333
request: {
3434
token: underlyingToken,
3535
chainId: inputs.chainId,
3636
},
37-
response: ['1000000000000000000'], // 1 USD = 1 USDC
37+
response: ['1000000000000000000'], // 1 USDC = 1 USD
3838
},
3939
]
4040

examples/07-withdraw-from-aave-swap-and-transfer/manifest.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ version: 1.0.0
22
name: Claim-Swap-Transfer Loop Task
33
description: This task is for demo purposes. It withdraws from AAVE, swaps for an AAVE token and transfer to deposit in loop
44
inputs:
5-
- usdFeeAmount: string
5+
- maxFeeUsdt: string # e.g., '0.5' = 0.5 USDT
66
- smartAccount: address
77
abis:
88
- AavePool: ./abis/AavePool.json

examples/07-withdraw-from-aave-swap-and-transfer/src/task.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,13 +47,13 @@ export default function main(): void {
4747
const usdcUser = findTokenAmount(userTokens, USDC)
4848
const aUsdcUser = findTokenAmount(userTokens, aUSDC)
4949

50-
const feeUsdt = TokenAmount.fromStringDecimal(USDT, inputs.usdFeeAmount)
50+
const maxFeeUsdt = TokenAmount.fromStringDecimal(USDT, inputs.maxFeeUsdt)
5151

5252
if (aUsdcSmartAccount && aUsdcSmartAccount.amount > BigInt.zero()) {
5353
// Claim aUSDC to user EOA using USDC in smart account
5454
aaveV3Pool
5555
.withdraw(USDC.address, aUsdcSmartAccount.amount, context.user)
56-
.addMaxFee(feeUsdt)
56+
.addMaxFee(maxFeeUsdt)
5757
.addUser(inputs.smartAccount)
5858
.build()
5959
.send()
@@ -73,7 +73,7 @@ export default function main(): void {
7373
// Transfer aUSDC from user EOA to smart account
7474
TransferBuilder.forChain(chainId)
7575
.addTransfer(new TransferData(aUSDC.address, aUsdcUser.amount, inputs.smartAccount))
76-
.addMaxFee(feeUsdt)
76+
.addMaxFee(maxFeeUsdt)
7777
.build()
7878
.send()
7979
}

examples/07-withdraw-from-aave-swap-and-transfer/tests/task.spec.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Chains, OpType } from '@mimicprotocol/sdk'
1+
import { Chains, OpType, randomEvmAddress } from '@mimicprotocol/sdk'
22
import {
33
Call,
44
Context,
@@ -23,15 +23,15 @@ describe('Task', () => {
2323
}
2424

2525
const context: Context = {
26-
user: '0xae7168deb525862f4fee37d987a971b385b96952',
27-
settlers: [{ address: '0xdcf1d9d12a0488dfb70a8696f44d6d3bc303963d', chainId: 10 }],
26+
user: randomEvmAddress(),
27+
settlers: [{ address: randomEvmAddress(), chainId: 10 }],
2828
timestamp: Date.now(),
2929
}
3030

3131
const inputs = {
3232
chainId,
33-
smartAccount: '0x863df6bfa4469f3ead0be8f9f2aae51c91a907b4',
34-
usdFeeAmount: '1', // 1 USD in USDT
33+
smartAccount: randomEvmAddress(),
34+
maxFeeUsdt: '1', // 1 USDT
3535
}
3636

3737
const calls: ContractCallMock[] = [

examples/08-relevant-tokens-query/manifest.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,5 @@ name: Relevant tokens query example
33
description: Example of how to use the relevant tokens query
44
inputs:
55
- chainId: int32
6-
- feeAmountUsd: string # e.g., '1.5' = 1.5 USD
6+
- maxFeeUsd: string # e.g., '1.5' = 1.5 USD
77
- recipient: address

examples/08-relevant-tokens-query/src/task.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,5 +18,5 @@ export default function main(): void {
1818
return
1919
}
2020

21-
builder.addMaxFee(TokenAmount.fromStringDecimal(DenominationToken.USD(), inputs.feeAmountUsd)).build().send()
21+
builder.addMaxFee(TokenAmount.fromStringDecimal(DenominationToken.USD(), inputs.maxFeeUsd)).build().send()
2222
}

0 commit comments

Comments
 (0)