Skip to content

Commit

Permalink
Revert "[worker] test all endianness in unit tests"
Browse files Browse the repository at this point in the history
This reverts commit c8f69f1.
  • Loading branch information
clangenb committed May 1, 2024
1 parent c8f69f1 commit b6ee1c4
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 78 deletions.
68 changes: 6 additions & 62 deletions packages/worker-api/src/integriteeWorker.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,88 +72,32 @@ describe('worker', () => {
});
});

// describe('balance transfer should work', () => {
// it('should return value', async () => {
// const shard = network.chosenCid;
// const result = await worker.trustedBalanceTransfer(
// alice,
// shard,
// network.mrenclave,
// alice.address,
// charlie.address,
// 1100000000000
// );
// console.log('balance transfer result', result.toHuman());
// expect(result).toBeDefined();
// });
// });

describe('balance unshield should work be/be', () => {
describe('balance transfer should work', () => {
it('should return value', async () => {
const shard = network.chosenCid;

const result = await worker.balanceUnshieldFunds(
const result = await worker.trustedBalanceTransfer(
alice,
shard,
network.mrenclave,
alice.address,
charlie.address,
1100000000000,
{inputEndian: "be", outputEndian: "be"}
1100000000000
);
console.log('balance unshield result', result.toHuman());
console.log('balance transfer result', result.toHuman());
expect(result).toBeDefined();
});
});

describe('balance unshield should work be/le', () => {
describe('balance unshield should work', () => {
it('should return value', async () => {
const shard = network.chosenCid;

const result = await worker.balanceUnshieldFunds(
alice,
shard,
network.mrenclave,
alice.address,
charlie.address,
1100000000000,
{inputEndian: "be", outputEndian: "le"}
);
console.log('balance unshield result', result.toHuman());
expect(result).toBeDefined();
});
});

describe('balance unshield should work le/be', () => {
it('should return value', async () => {
const shard = network.chosenCid;

const result = await worker.balanceUnshieldFunds(
alice,
shard,
network.mrenclave,
alice.address,
charlie.address,
1100000000000,
{inputEndian: "le", outputEndian: "be"}
);
console.log('balance unshield result', result.toHuman());
expect(result).toBeDefined();
});
});

describe('balance unshield should work le/le', () => {
it('should return value', async () => {
const shard = network.chosenCid;

const result = await worker.balanceUnshieldFunds(
alice,
shard,
network.mrenclave,
alice.address,
charlie.address,
1100000000000,
{inputEndian: "le", outputEndian: "le"}
1100000000000
);
console.log('balance unshield result', result.toHuman());
expect(result).toBeDefined();
Expand Down
9 changes: 3 additions & 6 deletions packages/worker-api/src/interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,14 @@ import {Keyring} from "@polkadot/keyring";
import type {u8} from "@polkadot/types-codec";
import type {TypeRegistry, Vec} from "@polkadot/types";
import type {RegistryTypes} from "@polkadot/types/types";
import BN from "bn.js";

export interface IWorker extends WebSocketAsPromised {
rsCount: number;
rqStack: string[];
keyring: () => Keyring | undefined;
createType: (apiType: string, obj?: any) => any;
open: () => Promise<Event>;
encrypt: (data: Uint8Array, inputEndian?: BN.Endianness, outputEndian?: BN.Endianness) => Promise<Vec<u8>>
encrypt: (data: Uint8Array) => Promise<Vec<u8>>
registry: () => TypeRegistry
}

Expand Down Expand Up @@ -50,10 +49,8 @@ export interface PublicGetterArgs {
export type RequestArgs = PublicGetterArgs | TrustedGetterArgs | { }

export interface CallOptions {
timeout?: number;
debug?: boolean;
inputEndian?: BN.Endianness;
outputEndian?: BN.Endianness;
timeout: number;
debug: boolean;
}

export enum Request {
Expand Down
14 changes: 4 additions & 10 deletions packages/worker-api/src/worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import {parseBalance} from './parsers.js';
import {callGetter} from './sendRequest.js';
import {parseWebCryptoRSA, encryptWithPublicKey} from "./webCryptoRSA.js";
import type {u8} from "@polkadot/types-codec";
import BN from "bn.js";

const unwrapWorkerResponse = (self: IWorker, data: string) => {
/// Defaults to return `[]`, which is fine as `createType(api.registry, <type>, [])`
Expand Down Expand Up @@ -116,16 +115,11 @@ export class Worker extends WebSocketAsPromised implements IWorker {
}
}

public async encrypt(data: Uint8Array, inputEndian: BN.Endianness = 'le', outputEndian: BN.Endianness = 'le'): Promise<Vec<u8>> {
const dataBE = new BN(data, inputEndian);
const dataArrayBE = new Uint8Array(dataBE.toArray());

const cypherTextBuffer = await encryptWithPublicKey(dataArrayBE, this.shieldingKey() as CryptoKey);
public async encrypt(data: Uint8Array): Promise<Vec<u8>> {
// @ts-ignore
const cypherTextBuffer = await encryptWithPublicKey(data, this.shieldingKey() as CryptoKey);
const cypherArray = new Uint8Array(cypherTextBuffer);

const be = new BN(cypherArray, outputEndian)
const beArray = new Uint8Array(be.toArray());
return this.createType('Vec<u8>', compactAddLength(beArray))
return this.createType('Vec<u8>', compactAddLength(cypherArray))
}

public registry(): TypeRegistry {
Expand Down

0 comments on commit b6ee1c4

Please sign in to comment.