Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion modules/sdk-coin-dot/src/lib/txnSchema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export const BaseTransactionSchema = joi.object({
blockHash: joi.string().required(),
genesisHash: joi.string().required(),
specVersion: joi.number().required(),
specName: joi.string().valid('kusama', 'polkadot', 'westend', 'statemint', 'statemine', 'westmint').required(),
specName: joi.string().valid('kusama', 'polkadot', 'westend', 'statemint', 'statemine').required(),
transactionVersion: joi.number().required(),
chainName: joi.string().required(),
eraPeriod: joi.number().required(),
Expand Down
10 changes: 2 additions & 8 deletions modules/sdk-coin-dot/src/lib/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ import {
UnstakeBatchCallArgs,
} from './iface';
import { KeyPair } from '.';
import { mainnetMetadataRpc, westendMetadataRpc, westendAssetHubMetadataRpc } from '../resources';
import { mainnetMetadataRpc, westendMetadataRpc } from '../resources';

const PROXY_METHOD_ARG = 2;
// map to retrieve the address encoding format when the key is the asset name
Expand Down Expand Up @@ -255,13 +255,7 @@ export class Utils implements BaseUtils {
getMaterial(coinConfig: Readonly<CoinConfig>): Material {
const networkConfig = coinConfig.network as DotNetwork;
const { specName, specVersion, chainName, txVersion, genesisHash } = networkConfig;
let metadataRpc = mainnetMetadataRpc;

if (specName === 'westend') {
metadataRpc = westendMetadataRpc;
} else if (specName === 'westmint') {
metadataRpc = westendAssetHubMetadataRpc;
}
const metadataRpc = networkConfig.specName === 'westend' ? westendMetadataRpc : mainnetMetadataRpc;

return {
specName,
Expand Down
1 change: 0 additions & 1 deletion modules/sdk-coin-dot/src/resources/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
export * from './mainnet';
export * from './westend';
export * from './westendAssetHub';
2 changes: 0 additions & 2 deletions modules/sdk-coin-dot/src/resources/westendAssetHub.ts

This file was deleted.

This file was deleted.

94 changes: 52 additions & 42 deletions modules/sdk-coin-dot/test/resources/index.ts

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions modules/sdk-coin-dot/test/unit/dot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,12 @@ describe('DOT:', function () {
sender: '5EGoFA95omzemRssELLDjVenNZ68aXyUeqtKQScXSEBvVJkr',
referenceBlock: '0x149799bc9602cb5cf201f3425fb8d253b2d4e61fc119dcab3249f307f594754d',
blockNumber: 3933,
genesisHash: '0x67f9723393ef76214df0118c34bbbd3dbebc8ed46a10973a8c969d48fe7598c9',
genesisHash: '0xe143f23803ac50e8f6f8e62695d1ce9e4e1d68aa36c1cd2cfd15340213f3423e',
nonce: 200,
specVersion: 1018013,
transactionVersion: 16,
specVersion: 9150,
transactionVersion: 8,
eraPeriod: 64,
chainName: 'Westend Asset Hub',
chainName: 'Westend',
tip: 0,
to: '5Ffp1wJCPu4hzVDTo7XaMLqZSvSadyUQmxWPDw74CBjECSoq',
amount: '10000000000',
Expand Down
12 changes: 6 additions & 6 deletions modules/sdk-coin-dot/test/unit/transaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,15 +89,15 @@ describe('Dot Transaction', () => {

it('Should rebuild different hex if keepAlive is true or false for transferAll txs', async () => {
const keepAliveFalseBuilder = new TransferBuilder(config).material(material);
keepAliveFalseBuilder.from(rawTx.transfer.unsigned);
keepAliveFalseBuilder.from(rawTx.transferAll.unsignedKeepAliveFalse);
keepAliveFalseBuilder
.validity({ firstValid: 3933 })
.referenceBlock('0x149799bc9602cb5cf201f3425fb8d253b2d4e61fc119dcab3249f307f594754d')
.sender({ address: accounts.account1.address });
const keepAliveFalseTx = (await keepAliveFalseBuilder.build()).toJson();

const keepAliveTrueBuilder = new TransferBuilder(config).material(material);
keepAliveTrueBuilder.from(rawTx.transferAll.signed);
keepAliveTrueBuilder.from(rawTx.transferAll.unsignedKeepAliveTrue);
keepAliveTrueBuilder
.validity({ firstValid: 3933 })
.referenceBlock('0x149799bc9602cb5cf201f3425fb8d253b2d4e61fc119dcab3249f307f594754d')
Expand Down Expand Up @@ -219,7 +219,7 @@ describe('Dot Transaction', () => {

// Add proxy storage fee
should(tx.inputs[1].address).eql(accounts.account1.address);
should(tx.inputs[1].value).eql('10036500000');
should(tx.inputs[1].value).eql('1002050000000');
should(tx.inputs[1].coin).eql('tdot');

should(tx.outputs).not.be.null();
Expand All @@ -232,7 +232,7 @@ describe('Dot Transaction', () => {

// Add proxy storage fee
should(tx.outputs[1].address).eql(accounts.stakingProxy.address);
should(tx.outputs[1].value).eql('10036500000');
should(tx.outputs[1].value).eql('1002050000000');
should(tx.outputs[1].coin).eql('tdot');
});

Expand All @@ -250,15 +250,15 @@ describe('Dot Transaction', () => {

// Remove proxy storage fee refund
should(tx.inputs[0].address).eql(accounts.stakingProxy.address);
should(tx.inputs[0].value).eql('10036500000');
should(tx.inputs[0].value).eql('1002050000000');
should(tx.inputs[0].coin).eql('tdot');

should(tx.outputs).not.be.null();
should(tx.outputs.length).eql(1);

// Remove proxy storage fee refund
should(tx.outputs[0].address).eql(accounts.account1.address);
should(tx.outputs[0].value).eql('10036500000');
should(tx.outputs[0].value).eql('1002050000000');
should(tx.outputs[0].coin).eql('tdot');
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ describe('Dot Address Initialization Builder', () => {
should.deepEqual(txJson.sender, sender.address);
should.deepEqual(txJson.blockNumber, 8975007);
should.deepEqual(txJson.referenceBlock, '0x9ed0c8ee5fdc375ee57f79591d7d0db4d7cd2aa0e5403a2ed84edf0f859e3f05');
should.deepEqual(txJson.genesisHash, '0x67f9723393ef76214df0118c34bbbd3dbebc8ed46a10973a8c969d48fe7598c9');
should.deepEqual(txJson.genesisHash, '0xe143f23803ac50e8f6f8e62695d1ce9e4e1d68aa36c1cd2cfd15340213f3423e');
should.deepEqual(txJson.nonce, 200);
should.deepEqual(txJson.tip, 0);
should.deepEqual(txJson.transactionVersion, txVersion);
Expand All @@ -272,7 +272,7 @@ describe('Dot Address Initialization Builder', () => {
should.deepEqual(txJson.sender, sender.address);
should.deepEqual(txJson.blockNumber, 8975007);
should.deepEqual(txJson.referenceBlock, '0x9ed0c8ee5fdc375ee57f79591d7d0db4d7cd2aa0e5403a2ed84edf0f859e3f05');
should.deepEqual(txJson.genesisHash, '0x67f9723393ef76214df0118c34bbbd3dbebc8ed46a10973a8c969d48fe7598c9');
should.deepEqual(txJson.genesisHash, '0xe143f23803ac50e8f6f8e62695d1ce9e4e1d68aa36c1cd2cfd15340213f3423e');
should.deepEqual(txJson.nonce, 200);
should.deepEqual(txJson.tip, 0);
should.deepEqual(txJson.transactionVersion, txVersion);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ describe('Dot Batch Transaction Builder', () => {
describe('build batch transaction', function () {
const sender = accounts.account1;
const referenceBlock = '0x462ab5246361febb9294ffa41dd099edddec30a205ea15fbd247abb0ddbabd51';
const genesisHash = '0x67f9723393ef76214df0118c34bbbd3dbebc8ed46a10973a8c969d48fe7598c9';
const genesisHash = '0xe143f23803ac50e8f6f8e62695d1ce9e4e1d68aa36c1cd2cfd15340213f3423e';

beforeEach(() => {
const config = buildTestConfig();
Expand Down Expand Up @@ -67,7 +67,7 @@ describe('Dot Batch Transaction Builder', () => {
should.deepEqual(txJson.nonce, 0);
should.deepEqual(txJson.tip, 0);
should.deepEqual(txJson.transactionVersion, txVersion);
should.deepEqual(txJson.chainName, 'Westend Asset Hub');
should.deepEqual(txJson.chainName, 'Westend');
should.deepEqual(txJson.eraPeriod, 64);

const txHex = tx.toBroadcastFormat();
Expand Down Expand Up @@ -104,7 +104,7 @@ describe('Dot Batch Transaction Builder', () => {
should.deepEqual(txJson.nonce, 0);
should.deepEqual(txJson.tip, 0);
should.deepEqual(txJson.transactionVersion, txVersion);
should.deepEqual(txJson.chainName, 'Westend Asset Hub');
should.deepEqual(txJson.chainName, 'Westend');
should.deepEqual(txJson.eraPeriod, 64);

const txHex = tx.toBroadcastFormat();
Expand Down Expand Up @@ -140,7 +140,7 @@ describe('Dot Batch Transaction Builder', () => {
should.deepEqual(txJson.nonce, 0);
should.deepEqual(txJson.tip, 0);
should.deepEqual(txJson.transactionVersion, txVersion);
should.deepEqual(txJson.chainName, 'Westend Asset Hub');
should.deepEqual(txJson.chainName, 'Westend');
should.deepEqual(txJson.eraPeriod, 64);

const txHex = tx.toBroadcastFormat();
Expand Down Expand Up @@ -177,14 +177,45 @@ describe('Dot Batch Transaction Builder', () => {
should.deepEqual(txJson.nonce, 0);
should.deepEqual(txJson.tip, 0);
should.deepEqual(txJson.transactionVersion, txVersion);
should.deepEqual(txJson.chainName, 'Westend Asset Hub');
should.deepEqual(txJson.chainName, 'Westend');
should.deepEqual(txJson.eraPeriod, 64);

const txHex = tx.toBroadcastFormat();
should.deepEqual(rawTx.unstake.batchAll.signed, txHex);
});

describe('from raw', () => {
it('should build a batch from a raw signed tx', async () => {
builder.from(rawTx.batch.threeAddPureProxies.signed);
builder.validity({ firstValid: 9266787, maxDuration: 64 }).referenceBlock(referenceBlock);
const tx = await builder.build();
const txJson = tx.toJson();
// test the call items
should.deepEqual(txJson.sender, sender.address);
should.deepEqual(txJson.batchCalls.length, 3);
should.deepEqual(txJson.batchCalls[0].args?.proxy_type, ProxyType.ANY);
should.deepEqual(txJson.batchCalls[0].args?.delay, 0);
should.deepEqual(txJson.batchCalls[0].args?.index, 0);
should.deepEqual(txJson.batchCalls[1].args?.proxy_type, ProxyType.ANY);
should.deepEqual(txJson.batchCalls[1].args?.delay, 0);
should.deepEqual(txJson.batchCalls[1].args?.index, 1);
should.deepEqual(txJson.batchCalls[2].args?.proxy_type, ProxyType.ANY);
should.deepEqual(txJson.batchCalls[2].args?.delay, 0);
should.deepEqual(txJson.batchCalls[2].args?.index, 2);
should.deepEqual(txJson.blockNumber, 9266787);
should.deepEqual(txJson.referenceBlock, referenceBlock);
should.deepEqual(txJson.genesisHash, genesisHash);
should.deepEqual(txJson.specVersion, specVersion);
should.deepEqual(txJson.nonce, 0);
should.deepEqual(txJson.tip, 0);
should.deepEqual(txJson.transactionVersion, txVersion);
should.deepEqual(txJson.chainName, 'Westend');
should.deepEqual(txJson.eraPeriod, 64);

const txHex = tx.toBroadcastFormat();
should.deepEqual(rawTx.batch.threeAddPureProxies.signed, txHex);
});

it('should build a batch all from a raw signed tx', async () => {
builder.from(rawTx.batchAll.twoAddPureProxies.signed);
builder.validity({ firstValid: 9279281, maxDuration: 64 }).referenceBlock(referenceBlock);
Expand All @@ -206,7 +237,7 @@ describe('Dot Batch Transaction Builder', () => {
should.deepEqual(txJson.nonce, 0);
should.deepEqual(txJson.tip, 0);
should.deepEqual(txJson.transactionVersion, txVersion);
should.deepEqual(txJson.chainName, 'Westend Asset Hub');
should.deepEqual(txJson.chainName, 'Westend');
should.deepEqual(txJson.eraPeriod, 64);

const txHex = tx.toBroadcastFormat();
Expand Down Expand Up @@ -236,7 +267,7 @@ describe('Dot Batch Transaction Builder', () => {
should.deepEqual(txJson.nonce, 0);
should.deepEqual(txJson.tip, 0);
should.deepEqual(txJson.transactionVersion, txVersion);
should.deepEqual(txJson.chainName, 'Westend Asset Hub');
should.deepEqual(txJson.chainName, 'Westend');
should.deepEqual(txJson.eraPeriod, 64);

const txHex = tx.toBroadcastFormat();
Expand Down Expand Up @@ -268,7 +299,7 @@ describe('Dot Batch Transaction Builder', () => {
should.deepEqual(txJson.nonce, 0);
should.deepEqual(txJson.tip, 0);
should.deepEqual(txJson.transactionVersion, txVersion);
should.deepEqual(txJson.chainName, 'Westend Asset Hub');
should.deepEqual(txJson.chainName, 'Westend');
should.deepEqual(txJson.eraPeriod, 64);

const txHex = tx.toBroadcastFormat();
Expand Down Expand Up @@ -306,7 +337,7 @@ describe('Dot Batch Transaction Builder', () => {
should.deepEqual(txJson.nonce, 200);
should.deepEqual(txJson.tip, 0);
should.deepEqual(txJson.transactionVersion, txVersion);
should.deepEqual(txJson.chainName, 'Westend Asset Hub');
should.deepEqual(txJson.chainName, 'Westend');
should.deepEqual(txJson.eraPeriod, 64);

const txHex = tx.toBroadcastFormat();
Expand Down Expand Up @@ -342,7 +373,7 @@ describe('Dot Batch Transaction Builder', () => {
should.deepEqual(txJson.nonce, 200);
should.deepEqual(txJson.tip, 0);
should.deepEqual(txJson.transactionVersion, txVersion);
should.deepEqual(txJson.chainName, 'Westend Asset Hub');
should.deepEqual(txJson.chainName, 'Westend');
should.deepEqual(txJson.eraPeriod, 64);

const txHex = tx.toBroadcastFormat();
Expand Down Expand Up @@ -377,7 +408,7 @@ describe('Dot Batch Transaction Builder', () => {
should.deepEqual(txJson.nonce, 0);
should.deepEqual(txJson.tip, 0);
should.deepEqual(txJson.transactionVersion, txVersion);
should.deepEqual(txJson.chainName, 'Westend Asset Hub');
should.deepEqual(txJson.chainName, 'Westend');
should.deepEqual(txJson.eraPeriod, 64);

const txHex = tx.toBroadcastFormat();
Expand Down Expand Up @@ -412,7 +443,7 @@ describe('Dot Batch Transaction Builder', () => {
should.deepEqual(txJson.nonce, 0);
should.deepEqual(txJson.tip, 0);
should.deepEqual(txJson.transactionVersion, txVersion);
should.deepEqual(txJson.chainName, 'Westend Asset Hub');
should.deepEqual(txJson.chainName, 'Westend');
should.deepEqual(txJson.eraPeriod, 64);

const txHex = tx.toBroadcastFormat();
Expand Down Expand Up @@ -458,14 +489,48 @@ describe('Dot Batch Transaction Builder', () => {
should.deepEqual(txJson.nonce, 0);
should.deepEqual(txJson.tip, 0);
should.deepEqual(txJson.transactionVersion, txVersion);
should.deepEqual(txJson.chainName, 'Westend Asset Hub');
should.deepEqual(txJson.chainName, 'Westend');
should.deepEqual(txJson.eraPeriod, 64);

const txHex = tx.toBroadcastFormat();
should.deepEqual(rawTx.unstake.batchAll.unsigned, txHex);
});

describe('from raw', () => {
it('should build a batch from a raw unsigned tx', async () => {
builder.from(rawTx.batch.threeAddPureProxies.unsigned);
builder
.validity({ firstValid: 9266787, maxDuration: 64 })
.referenceBlock(referenceBlock)
.sender({ address: sender.address });

const tx = await builder.build();
const txJson = tx.toJson();
should.deepEqual(txJson.sender, sender.address);
should.deepEqual(txJson.batchCalls.length, 3);
should.deepEqual(txJson.batchCalls[0].args?.proxy_type, ProxyType.ANY);
should.deepEqual(txJson.batchCalls[0].args?.delay, 0);
should.deepEqual(txJson.batchCalls[0].args?.index, 0);
should.deepEqual(txJson.batchCalls[1].args?.proxy_type, ProxyType.ANY);
should.deepEqual(txJson.batchCalls[1].args?.delay, 0);
should.deepEqual(txJson.batchCalls[1].args?.index, 1);
should.deepEqual(txJson.batchCalls[2].args?.proxy_type, ProxyType.ANY);
should.deepEqual(txJson.batchCalls[2].args?.delay, 0);
should.deepEqual(txJson.batchCalls[2].args?.index, 2);
should.deepEqual(txJson.blockNumber, 9266787);
should.deepEqual(txJson.referenceBlock, referenceBlock);
should.deepEqual(txJson.genesisHash, genesisHash);
should.deepEqual(txJson.specVersion, specVersion);
should.deepEqual(txJson.nonce, 0);
should.deepEqual(txJson.tip, 0);
should.deepEqual(txJson.transactionVersion, txVersion);
should.deepEqual(txJson.chainName, 'Westend');
should.deepEqual(txJson.eraPeriod, 64);

const txHex = tx.toBroadcastFormat();
should.deepEqual(rawTx.batch.threeAddPureProxies.unsigned, txHex);
});

it('should build a batch all from a raw unsigned tx', async () => {
builder.from(rawTx.batchAll.twoAddPureProxies.unsigned);
builder
Expand All @@ -490,7 +555,7 @@ describe('Dot Batch Transaction Builder', () => {
should.deepEqual(txJson.nonce, 200);
should.deepEqual(txJson.tip, 0);
should.deepEqual(txJson.transactionVersion, txVersion);
should.deepEqual(txJson.chainName, 'Westend Asset Hub');
should.deepEqual(txJson.chainName, 'Westend');
should.deepEqual(txJson.eraPeriod, 64);

const txHex = tx.toBroadcastFormat();
Expand Down Expand Up @@ -524,7 +589,7 @@ describe('Dot Batch Transaction Builder', () => {
should.deepEqual(txJson.nonce, 0);
should.deepEqual(txJson.tip, 0);
should.deepEqual(txJson.transactionVersion, txVersion);
should.deepEqual(txJson.chainName, 'Westend Asset Hub');
should.deepEqual(txJson.chainName, 'Westend');
should.deepEqual(txJson.eraPeriod, 64);

const txHex = tx.toBroadcastFormat();
Expand Down Expand Up @@ -559,7 +624,7 @@ describe('Dot Batch Transaction Builder', () => {
should.deepEqual(txJson.nonce, 0);
should.deepEqual(txJson.tip, 0);
should.deepEqual(txJson.transactionVersion, txVersion);
should.deepEqual(txJson.chainName, 'Westend Asset Hub');
should.deepEqual(txJson.chainName, 'Westend');
should.deepEqual(txJson.eraPeriod, 64);

const txHex = tx.toBroadcastFormat();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import should from 'should';
import { SingletonRegistry } from '../../../src/lib';
import { TypeRegistry } from '@substrate/txwrapper-core/lib/types';
import { Material } from '../../../src/lib/iface';
import * as material from '../../resources/assetHubMaterialData.json';
import * as material from '../../resources/materialData.json';
import * as modifiedMaterial from '../../resources/materialDataModified.json';

describe('SingletonRegistry', function () {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
} from '../../../src/lib';
import { Material } from '../../../src/lib/iface';
import { rawTx, accounts, mockTssSignature } from '../../resources';
import * as materialData from '../../resources/assetHubMaterialData.json';
import * as materialData from '../../resources/materialData.json';

describe('dot Transaction Builder Factory', function () {
const sender = accounts.account1;
Expand Down
Loading