Skip to content

Commit

Permalink
Add TimestampedTrustedNote type and update BucketsInfo type (#122)
Browse files Browse the repository at this point in the history
* Add `TimestampedTrustedNote` type and update BucketsInfo type

* [test utils] update enclave fingerprint

* [integritee-worker] fix return type, replace TrustedNote with Timestamp trusted note.

* [integritee-worker] make the test more accurate

* [integritee-worker] make the test more accurate 2

* v0.17.0-alpha.2
  • Loading branch information
clangenb authored Nov 10, 2024
1 parent 3b980dc commit a86e9ed
Show file tree
Hide file tree
Showing 12 changed files with 63 additions and 30 deletions.
2 changes: 1 addition & 1 deletion lerna.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@
"publishConfig": {
"directory": "build"
},
"version": "0.17.0-alpha.1"
"version": "0.17.0-alpha.2"
}
4 changes: 2 additions & 2 deletions packages/node-api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@
},
"sideEffects": false,
"type": "module",
"version": "0.17.0-alpha.1",
"version": "0.17.0-alpha.2",
"main": "index.js",
"dependencies": {
"@encointer/types": "^0.17.0-alpha.1",
"@encointer/types": "^0.17.0-alpha.2",
"@polkadot/api": "^11.2.1",
"tslib": "^2.6.2"
},
Expand Down
2 changes: 1 addition & 1 deletion packages/types/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
},
"sideEffects": false,
"type": "module",
"version": "0.17.0-alpha.1",
"version": "0.17.0-alpha.2",
"main": "index.js",
"scripts": {
"generate:defs": "node --experimental-specifier-resolution=node --loader ts-node/esm ../../node_modules/.bin/polkadot-types-from-defs --package @encointer/types/interfaces --input ./src/interfaces",
Expand Down
3 changes: 2 additions & 1 deletion packages/types/src/interfaces/augment-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import type { Assignment, AssignmentCount, AssignmentParams, Attestation, Attest
import type { FixedI64F64, IpfsCid, PalletString } from '@encointer/types/interfaces/common';
import type { AnnouncementSigner, Bip340, CidDigest, CidName, CommunityCeremony, CommunityIdentifier, CommunityMetadataType, CommunityRules, DegreeFixed, DegreeRpc, GeoHash, Location, LocationRpc, NominalIncomeType } from '@encointer/types/interfaces/community';
import type { EncointerBalanceTransferArgs, EncointerGetter, EncointerGetterArgs, EncointerPublicGetter, EncointerTrustedCall, EncointerTrustedCallSigned, EncointerTrustedGetter, EncointerTrustedGetterSigned, GrantReputationArgs, RegisterAttestationsArgs, RegisterParticipantArgs } from '@encointer/types/interfaces/encointerWorker';
import type { AttemptsArg, BalanceShieldArgs, BalanceTransferArgs, BalanceTransferWithNoteArgs, BalanceUnshieldArgs, BucketIndex, BucketInfo, GuessArgs, GuessTheNumberInfo, GuessTheNumberPublicGetter, GuessTheNumberSetWinningsArgs, GuessTheNumberTrustedCall, GuessTheNumberTrustedGetter, GuessType, IntegriteeGetter, IntegriteePublicGetter, IntegriteeTrustedCall, IntegriteeTrustedCallSigned, IntegriteeTrustedGetter, IntegriteeTrustedGetterSigned, IntegriteeTrustedOperation, NoteIndex, NotesBucketInfo, NotesForArgs, TimestampSetArgs, TrustedNote } from '@encointer/types/interfaces/integriteeWorker';
import type { AttemptsArg, BalanceShieldArgs, BalanceTransferArgs, BalanceTransferWithNoteArgs, BalanceUnshieldArgs, BucketIndex, BucketInfo, GuessArgs, GuessTheNumberInfo, GuessTheNumberPublicGetter, GuessTheNumberSetWinningsArgs, GuessTheNumberTrustedCall, GuessTheNumberTrustedGetter, GuessType, IntegriteeGetter, IntegriteePublicGetter, IntegriteeTrustedCall, IntegriteeTrustedCallSigned, IntegriteeTrustedGetter, IntegriteeTrustedGetterSigned, IntegriteeTrustedOperation, NoteIndex, NotesBucketInfo, NotesForArgs, TimestampSetArgs, TimestampedTrustedNote, TrustedNote } from '@encointer/types/interfaces/integriteeWorker';
import type { SchedulerState, SystemNumber } from '@encointer/types/interfaces/scheduler';
import type { DirectRequestStatus, Enclave, EnclaveFingerprint, GetterArgs, ParentchainId, ParentchainInfo, ParentchainsInfo, Request, RpcReturnValue, ShardIdentifier, TrustedOperationStatus, Vault, WorkerEncoded } from '@encointer/types/interfaces/worker';
import type { Data, StorageKey } from '@polkadot/types';
Expand Down Expand Up @@ -1205,6 +1205,7 @@ declare module '@polkadot/types/types/registry' {
TAssetDepositBalance: TAssetDepositBalance;
Text: Text;
Timepoint: Timepoint;
TimestampedTrustedNote: TimestampedTrustedNote;
TimestampSetArgs: TimestampSetArgs;
TokenError: TokenError;
TombstoneContractInfo: TombstoneContractInfo;
Expand Down
12 changes: 10 additions & 2 deletions packages/types/src/interfaces/integriteeWorker/definitions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -196,15 +196,23 @@ export default {
NotesForArgs: '(AccountId, BucketIndex)',
BucketIndex: 'u32',
NoteIndex: 'u64',
TimestampedTrustedNote: {
timestamp: 'Moment',
version: 'u16',
note: 'TrustedNote'
},
TrustedNote: {
_enum: {
TrustedCall: 'Vec<u8>',
SgxRuntimeEvent: 'Vec<u8>'
SuccessfulTrustedCall: 'Vec<u8>',
SgxRuntimeEvent: 'Vec<u8>',
String: 'Text'
}
},
BucketInfo: {
index: 'BucketIndex',
bytes: 'u32',
begins_at: 'Moment',
ends_at: 'Moment',
},
NotesBucketInfo: {
first: 'Option<BucketInfo>',
Expand Down
19 changes: 15 additions & 4 deletions packages/types/src/interfaces/integriteeWorker/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

import type { BalanceType } from '@encointer/types/interfaces/balances';
import type { ParentchainId, ShardIdentifier } from '@encointer/types/interfaces/worker';
import type { Bytes, Enum, Option, Struct, Text, Vec, u32, u64 } from '@polkadot/types-codec';
import type { Bytes, Enum, Option, Struct, Text, Vec, u16, u32, u64 } from '@polkadot/types-codec';
import type { ITuple } from '@polkadot/types-codec/types';
import type { MultiSignature } from '@polkadot/types/interfaces/extrinsics';
import type { AccountId, Balance, H160, Moment } from '@polkadot/types/interfaces/runtime';
Expand Down Expand Up @@ -32,6 +32,8 @@ export interface BucketIndex extends u32 {}
export interface BucketInfo extends Struct {
readonly index: BucketIndex;
readonly bytes: u32;
readonly begins_at: Moment;
readonly ends_at: Moment;
}

/** @name GuessArgs */
Expand Down Expand Up @@ -302,16 +304,25 @@ export interface NotesBucketInfo extends Struct {
/** @name NotesForArgs */
export interface NotesForArgs extends ITuple<[AccountId, BucketIndex]> {}

/** @name TimestampedTrustedNote */
export interface TimestampedTrustedNote extends Struct {
readonly timestamp: Moment;
readonly version: u16;
readonly note: TrustedNote;
}

/** @name TimestampSetArgs */
export interface TimestampSetArgs extends ITuple<[AccountId, H160, BalanceType]> {}

/** @name TrustedNote */
export interface TrustedNote extends Enum {
readonly isTrustedCall: boolean;
readonly asTrustedCall: Bytes;
readonly isSuccessfulTrustedCall: boolean;
readonly asSuccessfulTrustedCall: Bytes;
readonly isSgxRuntimeEvent: boolean;
readonly asSgxRuntimeEvent: Bytes;
readonly type: 'TrustedCall' | 'SgxRuntimeEvent';
readonly isText: boolean;
readonly asText: Text;
readonly type: 'SuccessfulTrustedCall' | 'SgxRuntimeEvent' | 'Text';
}

export type PHANTOM_INTEGRITEEWORKER = 'integriteeWorker';
2 changes: 1 addition & 1 deletion packages/util/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"sideEffects": false,
"type": "module",
"types": "./index.d.ts",
"version": "0.17.0-alpha.1",
"version": "0.17.0-alpha.2",
"main": "index.js",
"dependencies": {
"@babel/runtime": "^7.18.9",
Expand Down
8 changes: 4 additions & 4 deletions packages/worker-api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@
"sideEffects": false,
"type": "module",
"types": "./index.d.ts",
"version": "0.17.0-alpha.1",
"version": "0.17.0-alpha.2",
"main": "index.js",
"dependencies": {
"@encointer/node-api": "^0.17.0-alpha.1",
"@encointer/types": "^0.17.0-alpha.1",
"@encointer/util": "^0.17.0-alpha.1",
"@encointer/node-api": "^0.17.0-alpha.2",
"@encointer/types": "^0.17.0-alpha.2",
"@encointer/util": "^0.17.0-alpha.2",
"@peculiar/webcrypto": "^1.4.6",
"@polkadot/api": "^11.2.1",
"@polkadot/keyring": "^12.6.2",
Expand Down
15 changes: 14 additions & 1 deletion packages/worker-api/src/integriteeWorker.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,14 +139,15 @@ describe('worker', () => {
describe('should return note of the executed trusted call', () => {
it('should return balance transfer with note as note', async () => {
const shard = network.shard;
const testNote = "My test note";
const result = await worker.trustedBalanceTransfer(
alice,
shard,
network.mrenclave,
alice.address,
charlie.address,
1100000000000,
"My test note"
testNote
);
console.log('balance transfer result', JSON.stringify(result));
expect(result).toBeDefined();
Expand All @@ -155,7 +156,19 @@ describe('worker', () => {
console.log(`notesForTrustedGetter: ${JSON.stringify(getter)}`);
const notes = await getter.send();
console.log('notesForTrustedGetter:', notes.toHuman());

// equal to 1 for a clean start, but it is more for subsequent runs.
expect(notes.length).toBeGreaterThanOrEqual(1);

// Check that the most recent note is the one we just sent before
const note = notes.pop()!;
expect(note.note.isSuccessfulTrustedCall);
const call = worker.createType('IntegriteeTrustedCall', note.note.asSuccessfulTrustedCall);
expect(call.isBalanceTransferWithNote);
expect(call.asBalanceTransferWithNote[3].toString()).toEqual(testNote)
expect(note.timestamp.toNumber() < Date.now());
const oneMinuteMs = 60 * 1000;
expect(note.timestamp.toNumber() > Date.now() - oneMinuteMs);
});
});

Expand Down
6 changes: 3 additions & 3 deletions packages/worker-api/src/integriteeWorker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import type {
GuessTheNumberTrustedGetter,
AttemptsArg,
ParentchainsInfo,
TrustedNote, NotesBucketInfo,
NotesBucketInfo, TimestampedTrustedNote,
} from '@encointer/types';
import {
type ISubmittableGetter,
Expand Down Expand Up @@ -67,14 +67,14 @@ export class IntegriteeWorker extends Worker {
}


public async notesForTrustedGetter(accountOrPubKey: AddressOrPair, bucketIndex: number, shard: string, signerOptions?: TrustedSignerOptions): Promise<SubmittableGetter<IntegriteeWorker, Vec<TrustedNote>>> {
public async notesForTrustedGetter(accountOrPubKey: AddressOrPair, bucketIndex: number, shard: string, signerOptions?: TrustedSignerOptions): Promise<SubmittableGetter<IntegriteeWorker, Vec<TimestampedTrustedNote>>> {
const trustedGetterArgs = {
shard: shard,
account: accountOrPubKey,
signer: signerOptions?.signer,
}
const notesForArgs = this.createType('NotesForArgs', [asString(accountOrPubKey), bucketIndex]);
return await submittableTrustedGetter<IntegriteeWorker, Vec<TrustedNote>>(this, 'notes_for', accountOrPubKey, trustedGetterArgs, notesForArgs,'Vec<TrustedNote>');
return await submittableTrustedGetter<IntegriteeWorker, Vec<TimestampedTrustedNote>>(this, 'notes_for', accountOrPubKey, trustedGetterArgs, notesForArgs,'Vec<TimestampedTrustedNote>');
}

public guessTheNumberInfoGetter(shard: string): SubmittableGetter<IntegriteeWorker, GuessTheNumberInfo> {
Expand Down
6 changes: 3 additions & 3 deletions packages/worker-api/src/testUtils/networks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@ export const localDockerNetwork = () => {
chain: 'ws://127.0.0.1:9944',
worker: 'wss://127.0.0.1:2000',
genesisHash: '0x388c446a804e24e77ae89f5bb099edb60cacc2ac7c898ce175bdaa08629c1439',
mrenclave: 'ExUoZaWmrqx2P3g77ERLzkkaaewdJP2atieSMbQHHGmq',
shard: 'ExUoZaWmrqx2P3g77ERLzkkaaewdJP2atieSMbQHHGmq',
chosenCid: 'ExUoZaWmrqx2P3g77ERLzkkaaewdJP2atieSMbQHHGmq',
mrenclave: 'GNKMuR4rnW54mcYqeAmNnH9Vibd6XsHdV2u62DgaG1bS',
shard: 'GNKMuR4rnW54mcYqeAmNnH9Vibd6XsHdV2u62DgaG1bS',
chosenCid: 'GNKMuR4rnW54mcYqeAmNnH9Vibd6XsHdV2u62DgaG1bS',
customTypes: {},
palletOverrides: {}
};
Expand Down
14 changes: 7 additions & 7 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -755,18 +755,18 @@ __metadata:
languageName: node
linkType: hard

"@encointer/node-api@npm:^0.17.0-alpha.1, @encointer/node-api@workspace:packages/node-api":
"@encointer/node-api@npm:^0.17.0-alpha.2, @encointer/node-api@workspace:packages/node-api":
version: 0.0.0-use.local
resolution: "@encointer/node-api@workspace:packages/node-api"
dependencies:
"@encointer/types": "npm:^0.17.0-alpha.1"
"@encointer/types": "npm:^0.17.0-alpha.2"
"@polkadot/api": "npm:^11.2.1"
"@polkadot/util-crypto": "npm:^12.6.2"
tslib: "npm:^2.6.2"
languageName: unknown
linkType: soft

"@encointer/types@npm:^0.17.0-alpha.1, @encointer/types@workspace:packages/types":
"@encointer/types@npm:^0.17.0-alpha.2, @encointer/types@workspace:packages/types":
version: 0.0.0-use.local
resolution: "@encointer/types@workspace:packages/types"
dependencies:
Expand All @@ -781,7 +781,7 @@ __metadata:
languageName: unknown
linkType: soft

"@encointer/util@npm:^0.17.0-alpha.1, @encointer/util@workspace:packages/util":
"@encointer/util@npm:^0.17.0-alpha.2, @encointer/util@workspace:packages/util":
version: 0.0.0-use.local
resolution: "@encointer/util@workspace:packages/util"
dependencies:
Expand All @@ -798,9 +798,9 @@ __metadata:
version: 0.0.0-use.local
resolution: "@encointer/worker-api@workspace:packages/worker-api"
dependencies:
"@encointer/node-api": "npm:^0.17.0-alpha.1"
"@encointer/types": "npm:^0.17.0-alpha.1"
"@encointer/util": "npm:^0.17.0-alpha.1"
"@encointer/node-api": "npm:^0.17.0-alpha.2"
"@encointer/types": "npm:^0.17.0-alpha.2"
"@encointer/util": "npm:^0.17.0-alpha.2"
"@peculiar/webcrypto": "npm:^1.4.6"
"@polkadot/api": "npm:^11.2.1"
"@polkadot/keyring": "npm:^12.6.2"
Expand Down

0 comments on commit a86e9ed

Please sign in to comment.