-
Notifications
You must be signed in to change notification settings - Fork 214
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
3 changed files
with
44 additions
and
0 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
22 changes: 22 additions & 0 deletions
22
packages/orchestration/test/tools/make-test-address.test.ts
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,22 @@ | ||
import test from '@endo/ses-ava/prepare-endo.js'; | ||
import { encodeAddressHook } from '@agoric/cosmic-proto/address-hooks.js'; | ||
import { makeTestAddress } from '../../tools/make-test-address.js'; | ||
|
||
test('makeTestAddress returns valid bech32', t => { | ||
t.is(makeTestAddress(), 'agoric1qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqp7zqht'); | ||
t.is(makeTestAddress(1), 'agoric1qyqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqc09z0g'); | ||
t.is( | ||
makeTestAddress(0, 'agoric', 32), | ||
'agoric1qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqkppep3', | ||
); | ||
t.is( | ||
makeTestAddress(0, 'cosmos'), | ||
'cosmos1qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqnrql8a', | ||
); | ||
}); | ||
|
||
test('makeTestAddress creates address accepted by encodeAddressHook', t => { | ||
const params = { EUD: makeTestAddress(0, 'osmosis') }; | ||
t.throws(() => encodeAddressHook('agoric1FakeLCAAddress', params)); | ||
t.notThrows(() => encodeAddressHook(makeTestAddress(), params)); | ||
}); |
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,21 @@ | ||
// eslint-disable-next-line import/no-extraneous-dependencies | ||
import { bech32 } from 'bech32'; | ||
|
||
/** | ||
* @param {number} index | ||
* @param {string} prefix | ||
* @param {number} byteLength | ||
* @returns {string} a mock bech32 address for tests | ||
*/ | ||
export const makeTestAddress = ( | ||
index = 0, | ||
prefix = 'agoric', | ||
byteLength = 20, | ||
) => { | ||
// create a simple 20-byte array (common address length) | ||
const bytes = new Uint8Array(byteLength).fill(0); | ||
// if index provided, put it in the first byte | ||
if (index !== 0) bytes[0] = Number(index); | ||
const words = bech32.toWords(bytes); | ||
return bech32.encode(prefix, words); | ||
}; |