-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: improve Dot Existential Deposit Test (#4195)
* added performAndTrackSwap: which create and execute a swap tracking all the relative events * added getSwapRate * added chain to broadcastId: we need to track the correct broadcaster, there can be different chain with the same broadcastId * add check before executing test * address comments * eslint * added checks to make the test runnable concurrently * added checks to make it run concurrently * fix RpcAsset error * addressed comments
- Loading branch information
1 parent
b9a975e
commit 9f336aa
Showing
8 changed files
with
233 additions
and
109 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
#!/usr/bin/env -S pnpm tsx | ||
import { getDotBalance } from './get_dot_balance'; | ||
import { performAndTrackSwap } from './perform_swap'; | ||
import { getSwapRate, newAddress } from './utils'; | ||
|
||
const DOT_EXISTENTIAL_DEPOSIT = 1; | ||
|
||
export async function swapLessThanED() { | ||
console.log('=== Testing USDC -> DOT swaps obtaining less than ED ==='); | ||
const tag = `USDC -> DOT (less than ED)`; | ||
|
||
// we will try to swap with 5 USDC and check if the expected output is low enough | ||
// otherwise we'll keep reducing the amount | ||
let retry = true; | ||
let inputAmount = '5'; | ||
while (retry) { | ||
let outputAmount = await getSwapRate('USDC', 'DOT', inputAmount); | ||
|
||
while (parseFloat(outputAmount) >= DOT_EXISTENTIAL_DEPOSIT) { | ||
inputAmount = (parseFloat(inputAmount) / 2).toString(); | ||
outputAmount = await getSwapRate('USDC', 'DOT', inputAmount); | ||
} | ||
console.log(`${tag} Input amount: ${inputAmount} USDC`); | ||
console.log(`${tag} Approximate expected output amount: ${outputAmount} DOT`); | ||
|
||
// we want to be sure to have an address with 0 balance, hence we create a new one every time | ||
const address = await newAddress( | ||
'DOT', | ||
'!testing less than ED output for dot swaps!' + inputAmount + outputAmount, | ||
); | ||
console.log(`${tag} Generated DOT address: ${address}`); | ||
|
||
await performAndTrackSwap('USDC', 'DOT', address, inputAmount, tag); | ||
// if for some reason the balance after swapping is > 0 it means that the output was larger than | ||
// ED, so we'll retry the test with a lower input | ||
if (parseFloat(await getDotBalance(address)) > 0) { | ||
console.log(`${tag}, swap output was more than ED, retrying with less...`); | ||
inputAmount = (parseFloat(inputAmount) / 3).toString(); | ||
} else { | ||
retry = false; | ||
} | ||
} | ||
console.log('=== Test USDC -> DOT swaps obtaining less than ED complete ==='); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
#!/usr/bin/env -S pnpm tsx | ||
import { swapLessThanED } from '../shared/swap_less_than_existential_deposit_dot'; | ||
import { runWithTimeout } from '../shared/utils'; | ||
|
||
async function main() { | ||
await swapLessThanED(); | ||
process.exit(0); | ||
} | ||
|
||
runWithTimeout(main(), 300000) | ||
.then(() => { | ||
// there are some dangling resources that prevent the process from exiting | ||
process.exit(0); | ||
}) | ||
.catch((error) => { | ||
console.error(error); | ||
process.exit(-1); | ||
}); |
Oops, something went wrong.