-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
update convert address integration tests & document known addrs
- Loading branch information
Showing
2 changed files
with
42 additions
and
29 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,45 +1,59 @@ | ||
import { commandSync } from 'execa'; | ||
import { CLI_PATH } from './helpers'; | ||
import { initEthKeyringPair, initKeyringPair } from '../../lib/account/keyring'; | ||
|
||
import { cryptoWaitReady } from '@polkadot/util-crypto'; | ||
|
||
let substrateSeedPhrase = ''; | ||
let substrateAccount = null; | ||
let substrateAddress = ''; | ||
let expectedAssociatedEvmAddress = ''; | ||
|
||
let evmSeedPhrase = ''; | ||
let evmAccount = null; | ||
let evmAddress = ''; | ||
let expectedAssociatedSubtrateAddress = ''; | ||
|
||
beforeAll(async () => { | ||
// Wait for crypto to be ready | ||
await cryptoWaitReady(); | ||
|
||
substrateSeedPhrase = 'wheel practice idle spin artefact unlock coffee yellow mirror pudding fetch supreme'; | ||
substrateAccount = initKeyringPair(substrateSeedPhrase); | ||
substrateAddress = substrateAccount.address; | ||
expectedAssociatedEvmAddress = '0x347557916f6abfc2b0862514b0e90708b422d992'; | ||
|
||
// EVM address (uses index 0) | ||
evmSeedPhrase = 'drift glove bar million spare better spot afford pave horn annual bunker'; | ||
evmAccount = initEthKeyringPair(evmSeedPhrase); | ||
evmAddress = evmAccount.address; | ||
expectedAssociatedSubtrateAddress = '5FQMKPxJuFBCeH7zQvwuKiRa3bMU41uYiumTkjXb1WeQxvf8'; | ||
}); | ||
|
||
describe('Convert Address command', () => { | ||
it('should convert a valid Substrate address', () => { | ||
const result = commandSync( | ||
`node ${CLI_PATH} convert-address --address 5HDRB6edmWwwh6aCDKrRSbisV8iFHdP7jDy18U2mt9w2wEkq`, | ||
); | ||
|
||
expect(result.stdout).toContain('0x'); | ||
}, 60000); | ||
|
||
it('should convert a valid EVM address', () => { | ||
const result = commandSync( | ||
`node ${CLI_PATH} convert-address --address 0xCb5705FbB64F1336c7cBaC018FB251930A753333`, | ||
); | ||
it('should NOT convert an invalid EVM address', () => { | ||
const result = commandSync(`node ${CLI_PATH} convert-address --address 0x123`, { reject: false }); | ||
|
||
expect(result.stdout).toContain('5'); | ||
expect(result.stderr).toContain('Not a valid Substrate or EVM address.'); | ||
}, 60000); | ||
|
||
it('should NOT convert an invalid address', () => { | ||
// Test that command fails with an invalid address | ||
const result = commandSync(`node ${CLI_PATH} convert-address --address 0x123`, { reject: false }); | ||
it('should NOT convert an invalid Substrate address', () => { | ||
const result = commandSync(`node ${CLI_PATH} convert-address --address 5FQMKPxJuFBCeH7zQvw0xa>>!jXb1WeQxvf8`, { | ||
reject: false, | ||
}); | ||
|
||
expect(result.stderr).toContain('Not a valid Substrate or EVM address.'); | ||
}, 60000); | ||
|
||
// Test a known convertion from Substrate to EVM works | ||
it('should convert a known Substrate address to a known EVM address', () => { | ||
const result = commandSync( | ||
`node ${CLI_PATH} convert-address --address 5HDRB6edmWwwh6aCDKrRSbisV8iFHdP7jDy18U2mt9w2wEkq`, | ||
); | ||
const result = commandSync(`node ${CLI_PATH} convert-address --address ${substrateAddress}`); | ||
|
||
expect(result.stdout.toLowerCase()).toContain('0xe3d237ebd67e011dbf48c34e5e4e936c5debe205'); | ||
expect(result.stdout.toLowerCase()).toContain(expectedAssociatedEvmAddress.toLowerCase()); | ||
}, 60000); | ||
|
||
// Test a known convertion from EVM to Substrate works | ||
it('should convert a known EVM address to a known Substrate address', () => { | ||
const result = commandSync( | ||
`node ${CLI_PATH} convert-address --address 0xCb5705FbB64F1336c7cBaC018FB251930A753333`, | ||
); | ||
const result = commandSync(`node ${CLI_PATH} convert-address --address ${evmAddress}`); | ||
|
||
expect(result.stdout).toContain('5EaVMBYdtn7jwhmtF17YYkYaju74hA5FZZuCWjHmwaWeMbK1'); | ||
expect(result.stdout.toLowerCase()).toContain(expectedAssociatedSubtrateAddress.toLowerCase()); | ||
}, 60000); | ||
}); |