Skip to content

Commit

Permalink
fix getting guess attempts, get the number info getter fails to be co…
Browse files Browse the repository at this point in the history
…nstructed for some reason.
  • Loading branch information
clangenb committed Oct 11, 2024
1 parent bc3d3ba commit 87695ea
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 7 deletions.
20 changes: 20 additions & 0 deletions packages/worker-api/src/integriteeWorker.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,26 @@ describe('worker', () => {
});
});

describe('getGuessTheNumberInfoGetter', () => {
it('should return value', async () => {
const getter = worker.getGuessTheNumberInfoGetter(network.mrenclave);
console.log(`GuessTheNumberInfo: ${JSON.stringify(getter)}`);
const result = await getter.send();
console.log('GuessTheNumberInfo:', result);
expect(result).toBeDefined();
});
});

describe('getGuessTheNumberAttemptsGetter', () => {
it('should return value', async () => {
const getter = await worker.guessTheNumberAttemptsTrustedGetter(charlie, network.mrenclave);
console.log(`Attempts: ${JSON.stringify(getter)}`);
const result = await getter.send();
console.log('Attempts:', result);
expect(result).toBeDefined();
});
});

// describe('balance transfer should work', () => {
// it('should return value', async () => {
// const shard = network.chosenCid;
Expand Down
5 changes: 3 additions & 2 deletions packages/worker-api/src/integriteeWorker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,9 @@ export class IntegriteeWorker extends Worker {
account: accountOrPubKey,
signer: signerOptions?.signer,
}

return await submittableGetter<IntegriteeWorker, AccountInfo>(this, 'account_info', accountOrPubKey, trustedGetterArgs, null,'AccountInfo');
const args = this.createType('AttemptsArg', {origin: asString(accountOrPubKey)});
const getterParams = guessTheNumberTrustedGetter(this, 'attempts', args);
return await submittableGetter<IntegriteeWorker, AccountInfo>(this, 'guess_the_number', accountOrPubKey, trustedGetterArgs, getterParams,'u8');
}

public async trustedBalanceTransfer(
Expand Down
14 changes: 9 additions & 5 deletions packages/worker-api/src/requests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
import type {
BalanceTransferArgs,
BalanceUnshieldArgs, GuessTheNumberTrustedCall,
IntegriteeGetter,
IntegriteeGetter, IntegriteePublicGetter,
IntegriteeTrustedCall,
IntegriteeTrustedCallSigned,
IntegriteeTrustedGetter,
Expand All @@ -18,19 +18,23 @@ import bs58 from "bs58";
import type {AddressOrPair} from "@polkadot/api-base/types/submittable";

export const createIntegriteeGetterPublic = (self: IWorker, request: string, publicGetterParams: PublicGetterParams) => {
const getter = self.createType('IntegriteePublicGetter', {
[request]: publicGetterParams
});
const getter = publicGetter(self, request, publicGetterParams);

const g = self.createType('IntegriteeGetter', {
public: {
getter,
getter
}
});

return g;
}

export function publicGetter(self: IWorker, request: string, publicGetterParams: PublicGetterParams): IntegriteePublicGetter {
return self.createType('IntegriteePublicGetter', {
[request]: publicGetterParams
});
}

export const createSignedGetter = async (self: IWorker, request: string, account: AddressOrPair, trustedGetterParams: TrustedGetterParams, options: TrustedSignerOptions) => {
const trustedGetter = createTrustedGetter(self, request, trustedGetterParams);
return await signTrustedGetter(self, account, trustedGetter, options);
Expand Down

0 comments on commit 87695ea

Please sign in to comment.