Skip to content

Commit

Permalink
Merge pull request #12 from AMIRKHANEF/SetMetadataTest
Browse files Browse the repository at this point in the history
address issue Sayfer.SAY-02: Add setMetadata test case
  • Loading branch information
Nick-1979 authored Feb 25, 2024
2 parents 1d4bda9 + a0175e6 commit a2f8792
Show file tree
Hide file tree
Showing 4 changed files with 404 additions and 5 deletions.
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@
"@polkadot/keyring": "^12.5.1",
"@polkadot/types": "^10.11.1",
"@polkadot/ui-keyring": "^3.6.3",
"@polkadot/util": "^12.5.1"
"@polkadot/util": "^12.5.1",
"chromedriver": "latest",
"webdriverio": "latest"
}
}
2 changes: 1 addition & 1 deletion packages/snap/snap.manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"url": "https://github.com/polkagate/snap.git"
},
"source": {
"shasum": "y/rum8DpJjyCJ58QW2hgMCBupeJcEZYuZRmDavMxQGI=",
"shasum": "4TiWO4/4fSB79wj6W5U/PywuXKP0MXc7NESoKpqF+J4=",
"location": {
"npm": {
"filePath": "dist/bundle.js",
Expand Down
66 changes: 66 additions & 0 deletions packages/snap/src/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import { Json, JsonRpcParams } from '@metamask/utils';
import { decodeAddress, signatureVerify } from '@polkadot/util-crypto';
import { u8aToHex, isHex } from '@polkadot/util';
import { ApiPromise, HttpProvider } from '@polkadot/api';
import { ExtDef } from '@polkadot/types/extrinsic/signedExtensions/types';
import type { MetadataDef } from '@polkadot/extension-inject/types';
import isValidAddress from '../../dapp/src/util/isValidAddress';
import { buildPayload } from '../../dapp/src/util/buildPayload';
import { getGenesisHash } from './chains';
Expand Down Expand Up @@ -37,6 +39,30 @@ const origin = 'Jest Test';
const sampleWestendAccountAddress = '5Cc8FwTx2nGbM26BdJqdseQBF8C1JeF1tbiabwPHa2UhB4fv';
let metamaskAccountAddr: string | undefined;

const types = {} as unknown as Record<string, string>;

const userExtensions = {
MyUserExtension: {
extrinsic: {
assetId: 'AssetId'
},
payload: {}
}
} as unknown as ExtDef;

const metadata: MetadataDef = {
chain: 'Development',
color: '#191a2e',
genesisHash: '0x242a54b35e1aad38f37b884eddeb71f6f9931b02fac27bf52dfb62ef754e5e62',
icon: '',
specVersion: 1000000,
ss58Format: 0,
tokenDecimals: 12,
tokenSymbol: '',
types,
userExtensions
};

describe('onRpcRequest', () => {
beforeAll(async () => {
const { request, close } = await installSnap();
Expand Down Expand Up @@ -294,4 +320,44 @@ describe('onRpcRequest', () => {

await close();
});

it('"setMetadata" RPC request method', async () => {
const { request } = await installSnap();

const expectedInterface = (
panel([
heading(`Update Request from ${origin}`),
divider(),
text(`Chain: **${metadata.chain}**`),
divider(),
text(`Token: **${metadata.tokenSymbol}**`),
divider(),
text(`Decimals: **${metadata.tokenDecimals}**`),
divider(),
text(`Spec Version: **${metadata.specVersion}**`),
divider(),
text(`Genesis Hash: **${metadata.genesisHash}**`),
])
);

const response = request({
method: 'setMetadata',
origin,
params: { metaData: metadata } as unknown as JsonRpcParams
});

const ui = await response.getInterface({ timeout: 50000 });


expect(ui.type).toBe('confirmation');
expect(ui.content).toEqual(expectedInterface);

await ui.ok();

const returnedValue = await response;

if ('result' in returnedValue.response) {
expect(returnedValue.response.result).toBeFalsy();
}
});
});
Loading

0 comments on commit a2f8792

Please sign in to comment.