Skip to content

Commit

Permalink
final tests
Browse files Browse the repository at this point in the history
  • Loading branch information
bee344 committed Jun 11, 2024
1 parent d14adf0 commit 6b78130
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
ASTAR_TEST_OPTIONS,
KUSAMA_TEST_OPTIONS,
signWithAlice,
signWithAliceAstar,
TEST_BASE_TX_INFO,
TEST_METHOD_ARGS,
} from '@substrate/txwrapper-dev';
Expand Down Expand Up @@ -38,7 +39,7 @@ describe('createSignedTx', () => {
ASTAR_TEST_OPTIONS,
);
const signingPayload = createSigningPayload(unsigned, ASTAR_TEST_OPTIONS);
const signature = await signWithAlice(signingPayload);
const signature = await signWithAliceAstar(signingPayload);

const tx = createSignedTx(unsigned, signature, ASTAR_TEST_OPTIONS);
expect(tx).toBe(
Expand Down
5 changes: 3 additions & 2 deletions packages/txwrapper-core/src/core/construct/getTxHash.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
ASTAR_TEST_OPTIONS,
KUSAMA_TEST_OPTIONS,
signWithAlice,
signWithAliceAstar,
TEST_BASE_TX_INFO,
TEST_METHOD_ARGS,
} from '@substrate/txwrapper-dev';
Expand Down Expand Up @@ -49,7 +50,7 @@ describe('getTxHash', () => {
unsigned,
ASTAR_TEST_OPTIONS,
);
const signature = await signWithAlice(signingPayload);
const signature = await signWithAliceAstar(signingPayload);
const signedTx = construct.signedTx(
unsigned,
signature,
Expand All @@ -58,7 +59,7 @@ describe('getTxHash', () => {

const txHash = getTxHash(signedTx);
expect(txHash).toBe(
'0x48598a4b920b83b931777088e6d1c9bcc1466518cb1ae0faa2a29553798e2f9c',
'0x1fc108525d6569889d53cbc092cba9c7ad0f59d668c60eff3447c774815d0485',
);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
ASTAR_TEST_OPTIONS,
KUSAMA_TEST_OPTIONS,
signWithAlice,
signWithAliceAstar,
TEST_BASE_TX_INFO,
TEST_METHOD_ARGS,
} from '@substrate/txwrapper-dev';
Expand Down Expand Up @@ -69,7 +70,7 @@ describe('decodeSignedTx', () => {
unsigned,
ASTAR_TEST_OPTIONS,
);
const signature = await signWithAlice(signingPayload);
const signature = await signWithAliceAstar(signingPayload);
const signedTx = construct.signedTx(
unsigned,
signature,
Expand Down
1 change: 1 addition & 0 deletions packages/txwrapper-dev/src/util/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
export * from './knownChainProperties';
export * from './signWithAlice';
export * from './signWithAliceAstar';
26 changes: 26 additions & 0 deletions packages/txwrapper-dev/src/util/signWithAliceAstar.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { Keyring } from '@polkadot/api';
import { cryptoWaitReady } from '@polkadot/util-crypto';

import { ASTAR_TEST_OPTIONS } from '../constants';

/**
* Sign a payload with seed `//Alice`.
*/
export async function signWithAliceAstar(
signingPayload: string,
): Promise<`0x${string}`> {
// We're creating an Alice account that will sign the payload
// Wait for the promise to resolve async WASM
await cryptoWaitReady();
// Use ed25519 because it has deterministic signatures
const keyring = new Keyring({ type: 'ed25519' });
const alice = keyring.addFromUri('//Alice', { name: 'Alice default' });

const { signature } = ASTAR_TEST_OPTIONS.registry
.createType('ExtrinsicPayload', signingPayload, {
version: 4,
})
.sign(alice);

return signature;
}

0 comments on commit 6b78130

Please sign in to comment.