Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
it('calculates the root correctly (actual)', () => {
expect(
root([
encodeUnchecked(keyring.nobody, 0)(
extrinsics.timestamp.public.set,
[0x5b13c3a4]
),
encodeUnchecked(keyring.nobody, 0)(
extrinsics.parachains.public.setHeads,
[[]]
)
])
).toEqual(
new Uint8Array([
140, 102, 133, 98, 214, 123, 73, 173, 122, 252, 247, 48, 181, 86, 77, 188, 213, 161, 17, 19, 73, 96, 158, 181, 249, 69, 97, 15, 186, 12, 45, 157
])
// hexToU8a(
// '0xab602f7974bbfb513f021f39777e2195094dc64a2c1b7c82a1781cb9fd4768a8'
// )
);
});
'6f000000' +
// prefix
'ff' +
'0000000000000000000000000000000000000000000000000000000000000000' +
'00000000' +
'0300' +
'7527000000000000' +
'0000000000000000000000000000000000000000000000000000000000000000' +
'0000000000000000000000000000000000000000000000000000000000000000'
)
)
).toMatchObject({
extrinsics: [
encodeUnchecked(
keyring.nobody, 0,
extrinsics.timestamp.public.set,
[10101]
)
]
});
});
});
'01000000' +
'6f000000' +
// prefix
'ff' +
'0000000000000000000000000000000000000000000000000000000000000000' +
'00000000' +
'0300' +
'7527000000000000' +
'0000000000000000000000000000000000000000000000000000000000000000' +
'0000000000000000000000000000000000000000000000000000000000000000'
)
)
).toMatchObject({
extrinsics: [
encodeUnchecked(keyring.nobody, 0)(
extrinsics.timestamp.public.set,
[10101]
)
]
});
});
});
// Copyright 2017-2018 @polkadot/client-wasm authors & contributors
// This software may be modified and distributed under the terms
// of the ISC license. See the LICENSE file for details.
import { UncheckedRaw } from '@polkadot/primitives/extrinsic';
import { ExecutorState } from '../types';
import extrinsics from '@polkadot/extrinsics';
import encodeUnchecked from '@polkadot/extrinsics/codec/encode/unchecked';
import testingKeypairs from '@polkadot/util-keyring/testingPairs';
const keyring = testingKeypairs();
const timestampSet = extrinsics.timestamp.public.set;
const parachainsSet = extrinsics.parachains.public.setHeads;
export default function inherentExtrinsics (self: ExecutorState, timestamp: number, _extrinsics: Array): Array {
return [
encodeUnchecked(keyring.nobody, 0)(
timestampSet,[timestamp]
),
encodeUnchecked(keyring.nobody, 0)(
parachainsSet, [[]]
)
].concat(_extrinsics);
}
it('applies the all transactions (extrinsicsRoot)', () => {
const transactions = [
encodeUnchecked(keyring.nobody, 0)(
extrinsics.timestamp.public.set,
[54321]
),
encodeUnchecked(keyring.one, 0)(
extrinsics.timestamp.public.set,
[12345]
)
];
expect(
header({}, transactions).extrinsicsRoot
).toEqual(
txRoot(transactions)
);
});
});
it('applies the all transactions (extrinsicsRoot)', () => {
const transactions = [
encodeUnchecked(
keyring.nobody, 0,
extrinsics.timestamp.public.set,
[54321]
),
encodeUnchecked(
keyring.one, 0,
extrinsics.timestamp.public.set,
[12345]
)
];
expect(
header({}, transactions).extrinsicsRoot
).toEqual(
txRoot(transactions)
);
});
});
it('applies the all transactions (extrinsicsRoot)', () => {
const transactions = [
encodeUnchecked(
keyring.nobody, 0,
extrinsics.timestamp.public.set,
[54321]
),
encodeUnchecked(
keyring.one, 0,
extrinsics.timestamp.public.set,
[12345]
)
];
expect(
header({}, transactions).extrinsicsRoot
).toEqual(
txRoot(transactions)
);
});
});
it('creates a valid block, with defaults submitted', () => {
const transactions = [
encodeUnchecked(
keyring.nobody, 0,
extrinsics.timestamp.public.set,
[0x5b13c3a4]
),
encodeUnchecked(
keyring.nobody, 0,
extrinsics.parachains.public.setHeads,
[[]]
)
];
expect(
block({
header: {
number: 1,
parentHash: hexToU8a(
'0x4545454545454545454545454545454545454545454545454545454545454545'
),
it('applies the all transactions (extrinsicsRoot)', () => {
const transactions = [
encodeUnchecked(keyring.nobody, 0)(
extrinsics.timestamp.public.set,
[54321]
),
encodeUnchecked(keyring.one, 0)(
extrinsics.timestamp.public.set,
[12345]
)
];
expect(
header({}, transactions).extrinsicsRoot
).toEqual(
txRoot(transactions)
);
});
});
module.exports = function inherentExtrinsics (self: ExecutorState, timestamp: number, _extrinsics: Array): Array {
return [
encodeUnchecked(keyring.nobody, 0)(
extrinsics.timestamp.public.set,
[timestamp]
),
encodeUnchecked(keyring.nobody, 0)(
extrinsics.parachains.public.setHeads,
[[]]
)
].concat(_extrinsics);
};