This repository has been archived by the owner on Oct 22, 2024. It is now read-only.
forked from paritytech/polkadot-sdk
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* added logging and updated metadata * separated tests which bootstrap the bridge * tested with v0.9.23 * add channel variables to example * revert example envrc
- Loading branch information
1 parent
abf5d2f
commit 73eec0b
Showing
6 changed files
with
82 additions
and
45 deletions.
There are no files selected for viewing
Binary file not shown.
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,67 @@ | ||
const Web3 = require('web3'); | ||
|
||
const BigNumber = require('bignumber.js'); | ||
|
||
const { expect } = require("chai") | ||
.use(require("chai-as-promised")) | ||
.use(require("chai-bignumber")(BigNumber)); | ||
|
||
const { treasuryAddressSS58, polkadotSenderSS58, | ||
polkadotRecipientSS58, polkadotRecipient, bootstrap } = require('../src/fixtures'); | ||
|
||
const { ChannelId } = require("../src/helpers"); | ||
|
||
describe('Bridge', function () { | ||
let ethClient, subClient, testSubClient; | ||
|
||
before(async function () { | ||
const clients = await bootstrap(); | ||
ethClient = clients.ethClient; | ||
subClient = clients.subClient; | ||
testSubClient = clients.testSubClient; | ||
this.testParaEthAssetId = 0; | ||
}); | ||
|
||
describe('Bootstrap', function () { | ||
it('should transfer DOT from Substrate to Ethereum (basic channel)', async function () { | ||
const amount = BigNumber('100000000000000'); // 100 DOT (12 decimal places in this environment) | ||
const amountWrapped = BigNumber(Web3.utils.toWei('100', "ether")); // 100 SnowDOT (18 decimal places) | ||
const ethAccount = ethClient.accounts[1]; | ||
|
||
const beforeEthBalance = await ethClient.getDotBalance(ethAccount); | ||
const beforeSubBalance = await subClient.queryAccountBalance(polkadotSenderSS58); | ||
|
||
// lock DOT using basic channel | ||
await subClient.lockDOT(subClient.alice, ethAccount, amount.toFixed(), ChannelId.BASIC) | ||
await ethClient.waitForNextEventData({ appName: 'snowDOT', eventName: 'Minted' }); | ||
|
||
const afterEthBalance = await ethClient.getDotBalance(ethAccount); | ||
const afterSubBalance = await subClient.queryAccountBalance(polkadotSenderSS58); | ||
|
||
expect(afterEthBalance.minus(beforeEthBalance)).to.be.bignumber.equal(amountWrapped); | ||
expect(beforeSubBalance.minus(afterSubBalance)).to.be.bignumber.greaterThan(amount); | ||
}); | ||
|
||
it('should transfer ETH from Ethereum to Substrate (incentivized channel)', async function () { | ||
const amount = BigNumber(Web3.utils.toWei('1', "ether")); | ||
const ethAccount = ethClient.accounts[1]; | ||
|
||
const subBalances = await subClient.subscribeAssetsAccountBalances( | ||
this.testParaEthAssetId, polkadotRecipientSS58, 2 | ||
); | ||
|
||
const beforeEthBalance = await ethClient.getEthBalance(ethAccount); | ||
const beforeSubBalance = await subBalances[0]; | ||
|
||
const { gasCost } = await ethClient.lockETH(ethAccount, amount, polkadotRecipient, ChannelId.INCENTIVIZED, 0, 0); | ||
|
||
const afterEthBalance = await ethClient.getEthBalance(ethAccount); | ||
const afterSubBalance = await subBalances[1]; | ||
|
||
expect(beforeEthBalance.minus(afterEthBalance)).to.be.bignumber.equal(amount.plus(gasCost)); | ||
expect(afterSubBalance.minus(beforeSubBalance)).to.be.bignumber.equal(amount); | ||
// conservation of value | ||
expect(beforeEthBalance.plus(beforeSubBalance)).to.be.bignumber.equal(afterEthBalance.plus(afterSubBalance).plus(gasCost)); | ||
}); | ||
}); | ||
}); |
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