diff --git a/lerna.json b/lerna.json index 2e85cf6..f6cff2d 100644 --- a/lerna.json +++ b/lerna.json @@ -6,5 +6,5 @@ "publishConfig": { "directory": "build" }, - "version": "0.17.0-alpha.1" + "version": "0.17.0-alpha.2" } diff --git a/packages/node-api/package.json b/packages/node-api/package.json index 04809f9..7d67c92 100644 --- a/packages/node-api/package.json +++ b/packages/node-api/package.json @@ -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" }, diff --git a/packages/types/package.json b/packages/types/package.json index e2593be..7ca0b36 100644 --- a/packages/types/package.json +++ b/packages/types/package.json @@ -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", diff --git a/packages/types/src/interfaces/augment-types.ts b/packages/types/src/interfaces/augment-types.ts index 2ec8efa..f0219cd 100644 --- a/packages/types/src/interfaces/augment-types.ts +++ b/packages/types/src/interfaces/augment-types.ts @@ -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'; @@ -1205,6 +1205,7 @@ declare module '@polkadot/types/types/registry' { TAssetDepositBalance: TAssetDepositBalance; Text: Text; Timepoint: Timepoint; + TimestampedTrustedNote: TimestampedTrustedNote; TimestampSetArgs: TimestampSetArgs; TokenError: TokenError; TombstoneContractInfo: TombstoneContractInfo; diff --git a/packages/types/src/interfaces/integriteeWorker/definitions.ts b/packages/types/src/interfaces/integriteeWorker/definitions.ts index d7ac94c..c6471b7 100644 --- a/packages/types/src/interfaces/integriteeWorker/definitions.ts +++ b/packages/types/src/interfaces/integriteeWorker/definitions.ts @@ -196,15 +196,23 @@ export default { NotesForArgs: '(AccountId, BucketIndex)', BucketIndex: 'u32', NoteIndex: 'u64', + TimestampedTrustedNote: { + timestamp: 'Moment', + version: 'u16', + note: 'TrustedNote' + }, TrustedNote: { _enum: { - TrustedCall: 'Vec', - SgxRuntimeEvent: 'Vec' + SuccessfulTrustedCall: 'Vec', + SgxRuntimeEvent: 'Vec', + String: 'Text' } }, BucketInfo: { index: 'BucketIndex', bytes: 'u32', + begins_at: 'Moment', + ends_at: 'Moment', }, NotesBucketInfo: { first: 'Option', diff --git a/packages/types/src/interfaces/integriteeWorker/types.ts b/packages/types/src/interfaces/integriteeWorker/types.ts index 9267269..93cb1cc 100644 --- a/packages/types/src/interfaces/integriteeWorker/types.ts +++ b/packages/types/src/interfaces/integriteeWorker/types.ts @@ -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'; @@ -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 */ @@ -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'; diff --git a/packages/util/package.json b/packages/util/package.json index 76cc8cb..90782e8 100644 --- a/packages/util/package.json +++ b/packages/util/package.json @@ -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", diff --git a/packages/worker-api/package.json b/packages/worker-api/package.json index 18b3bbd..20af5bc 100644 --- a/packages/worker-api/package.json +++ b/packages/worker-api/package.json @@ -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", diff --git a/packages/worker-api/src/integriteeWorker.spec.ts b/packages/worker-api/src/integriteeWorker.spec.ts index c0dc399..5351c0c 100644 --- a/packages/worker-api/src/integriteeWorker.spec.ts +++ b/packages/worker-api/src/integriteeWorker.spec.ts @@ -139,6 +139,7 @@ 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, @@ -146,7 +147,7 @@ describe('worker', () => { alice.address, charlie.address, 1100000000000, - "My test note" + testNote ); console.log('balance transfer result', JSON.stringify(result)); expect(result).toBeDefined(); @@ -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); }); }); diff --git a/packages/worker-api/src/integriteeWorker.ts b/packages/worker-api/src/integriteeWorker.ts index 2f8f1c8..efb1199 100644 --- a/packages/worker-api/src/integriteeWorker.ts +++ b/packages/worker-api/src/integriteeWorker.ts @@ -8,7 +8,7 @@ import type { GuessTheNumberTrustedGetter, AttemptsArg, ParentchainsInfo, - TrustedNote, NotesBucketInfo, + NotesBucketInfo, TimestampedTrustedNote, } from '@encointer/types'; import { type ISubmittableGetter, @@ -67,14 +67,14 @@ export class IntegriteeWorker extends Worker { } - public async notesForTrustedGetter(accountOrPubKey: AddressOrPair, bucketIndex: number, shard: string, signerOptions?: TrustedSignerOptions): Promise>> { + public async notesForTrustedGetter(accountOrPubKey: AddressOrPair, bucketIndex: number, shard: string, signerOptions?: TrustedSignerOptions): Promise>> { const trustedGetterArgs = { shard: shard, account: accountOrPubKey, signer: signerOptions?.signer, } const notesForArgs = this.createType('NotesForArgs', [asString(accountOrPubKey), bucketIndex]); - return await submittableTrustedGetter>(this, 'notes_for', accountOrPubKey, trustedGetterArgs, notesForArgs,'Vec'); + return await submittableTrustedGetter>(this, 'notes_for', accountOrPubKey, trustedGetterArgs, notesForArgs,'Vec'); } public guessTheNumberInfoGetter(shard: string): SubmittableGetter { diff --git a/packages/worker-api/src/testUtils/networks.ts b/packages/worker-api/src/testUtils/networks.ts index b5814ad..2a5b885 100644 --- a/packages/worker-api/src/testUtils/networks.ts +++ b/packages/worker-api/src/testUtils/networks.ts @@ -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: {} }; diff --git a/yarn.lock b/yarn.lock index 4ce1565..530782e 100644 --- a/yarn.lock +++ b/yarn.lock @@ -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: @@ -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: @@ -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"