From f50971dfae3f536c1720f0084f28afbcf5d99cb5 Mon Sep 17 00:00:00 2001 From: Alex Li Date: Wed, 22 May 2024 19:08:03 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20Fix=20encoder=20with=20deps=20an?= =?UTF-8?q?d=20format=20files=20(#77)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Resolves #76 --- CHANGELOG.md | 4 ++ lib/agent/actor.dart | 8 +-- lib/agent/agent.dart | 1 - lib/agent/agent/api.dart | 2 +- lib/agent/agent/http/types.dart | 12 ++-- lib/agent/auth.dart | 2 +- lib/agent/canisters/management_idl.dart | 10 +-- lib/agent/certificate.dart | 2 +- lib/agent/crypto/keystore/function.dart | 4 +- lib/agent/crypto/keystore/key_derivator.dart | 2 +- lib/agent/polling/strategy.dart | 2 +- lib/archiver/encoder.dart | 6 +- lib/auth_client/auth_client.dart | 2 +- lib/authentication/authentication.dart | 7 +- lib/bridge/wasm_interop.dart | 2 +- lib/candid/idl.dart | 12 ++-- lib/identity/der.dart | 2 +- lib/utils/bech32.dart | 4 +- lib/wallet/ledger.dart | 8 +-- lib/wallet/rosetta.dart | 10 +-- pubspec.yaml | 8 +-- test/agent/certificate.dart | 36 +++++----- test/candid/idl.dart | 70 ++++++++++---------- test/utils/is.dart | 2 +- 24 files changed, 110 insertions(+), 108 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 858da0c0..c8e692ca 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,10 @@ that can be found in the LICENSE file. --> # Changelog +## 1.0.0-dev.23 + +- Fix encoder with deps and format files. + ## 1.0.0-dev.22 - Correct invalid plugin references by marking FFI plugins. diff --git a/lib/agent/actor.dart b/lib/agent/actor.dart index ef3153ef..2f4359b6 100644 --- a/lib/agent/actor.dart +++ b/lib/agent/actor.dart @@ -22,7 +22,7 @@ class ActorCallError extends AgentFetchError { 'Call failed:', ' Canister: ${canisterId.toText()}', ' Method: $methodName ($type)', - ...(props.entries).map((n) => " '${n.key}': ${jsonEncode(props[n])}"), + ...props.entries.map((n) => " '${n.key}': ${jsonEncode(props[n])}"), ].join('\n'); throw e; } @@ -101,7 +101,7 @@ class CallConfig { 'agent': agent, 'pollingStrategyFactory': pollingStrategyFactory, 'canisterId': canisterId, - 'effectiveCanisterId': effectiveCanisterId + 'effectiveCanisterId': effectiveCanisterId, }; } } @@ -149,7 +149,7 @@ class ActorConfig extends CallConfig { return { ...super.toJson(), 'callTransform': callTransform, - 'queryTransform': queryTransform + 'queryTransform': queryTransform, }; } } @@ -251,7 +251,7 @@ class Actor { dynamic result; if (func != null) { result = await func.call([ - {'amount': [], 'settings': []} + {'amount': [], 'settings': []}, ]); } final canisterId = Principal.from(result['canister_id']); diff --git a/lib/agent/agent.dart b/lib/agent/agent.dart index 38d79cc0..27e25a80 100644 --- a/lib/agent/agent.dart +++ b/lib/agent/agent.dart @@ -1,4 +1,3 @@ -/// Sub folders export './agent/index.dart'; export './canisters/index.dart'; export './crypto/index.dart'; diff --git a/lib/agent/agent/api.dart b/lib/agent/agent/api.dart index 37755c5f..11ece963 100644 --- a/lib/agent/agent/api.dart +++ b/lib/agent/agent/api.dart @@ -170,7 +170,7 @@ abstract class Agent { Future status(); /// Send a query call to a canister. See - /// {@link https://sdk.dfinity.org/docs/interface-spec/#http-query | the interface spec}. + /// [the interface spec](https://sdk.dfinity.org/docs/interface-spec/#http-query). /// @param canisterId The Principal of the Canister to send the query to. Sending a query to /// the management canister is not supported (as it has no meaning from an agent). /// @param options Options to use to create and send the query. diff --git a/lib/agent/agent/http/types.dart b/lib/agent/agent/http/types.dart index 5ef4e797..8f8cad0d 100644 --- a/lib/agent/agent/http/types.dart +++ b/lib/agent/agent/http/types.dart @@ -209,12 +209,12 @@ typedef HttpAgentRequestTransformFnCall = Future Function( class HttpResponseBody extends ResponseBody { const HttpResponseBody({ - bool? ok, - int? status, - String? statusText, + super.ok, + super.status, + super.statusText, this.body, this.arrayBuffer, - }) : super(ok: ok, status: status, statusText: statusText); + }); factory HttpResponseBody.fromJson(Map map) { return HttpResponseBody( @@ -240,7 +240,7 @@ class HttpResponseBody extends ResponseBody { 'status': status, 'statusText': statusText, 'body': body, - 'arrayBuffer': arrayBuffer + 'arrayBuffer': arrayBuffer, }; } } @@ -320,7 +320,7 @@ class QueryResponseWithStatus extends QueryResponse { 'arg': reply?.arg, }, 'rejected_code': rejectCode, - 'rejected_message': rejectMessage + 'rejected_message': rejectMessage, }; } } diff --git a/lib/agent/auth.dart b/lib/agent/auth.dart index e10388bd..1199586f 100644 --- a/lib/agent/auth.dart +++ b/lib/agent/auth.dart @@ -98,7 +98,7 @@ class AnonymousIdentity implements Identity { Future> transformRequest(HttpAgentRequest request) { return Future.value({ ...request.toJson(), - 'body': {'content': request.body.toJson()} + 'body': {'content': request.body.toJson()}, }); } } diff --git a/lib/agent/canisters/management_idl.dart b/lib/agent/canisters/management_idl.dart index dd5dcb83..a6b52b43 100644 --- a/lib/agent/canisters/management_idl.dart +++ b/lib/agent/canisters/management_idl.dart @@ -12,17 +12,17 @@ Service managementIDL() { [ IDL.Record( {'amount': IDL.Opt(IDL.Nat), 'settings': IDL.Opt(canisterSettings)}, - ) + ), ], [ - IDL.Record({'canister_id': canisterId}) + IDL.Record({'canister_id': canisterId}), ], [], ), 'create_canister': IDL.Func( [], [ - IDL.Record({'canister_id': canisterId}) + IDL.Record({'canister_id': canisterId}), ], [], ), @@ -32,7 +32,7 @@ Service managementIDL() { 'mode': IDL.Variant({ 'install': IDL.Null, 'reinstall': IDL.Null, - 'upgrade': IDL.Null + 'upgrade': IDL.Null, }), 'canister_id': canisterId, 'wasm_module': wasmModule, @@ -46,7 +46,7 @@ Service managementIDL() { [ IDL.Record( {'canister_id': canisterId, 'new_controller': IDL.Principal}, - ) + ), ], [], [], diff --git a/lib/agent/certificate.dart b/lib/agent/certificate.dart index f33a8624..f1e9dfd9 100644 --- a/lib/agent/certificate.dart +++ b/lib/agent/certificate.dart @@ -69,7 +69,7 @@ class Cert { return { 'tree': tree, 'signature': signature, - 'delegation': delegation?.toJson() ?? {} + 'delegation': delegation?.toJson() ?? {}, }; } } diff --git a/lib/agent/crypto/keystore/function.dart b/lib/agent/crypto/keystore/function.dart index d8f58729..286d7f75 100644 --- a/lib/agent/crypto/keystore/function.dart +++ b/lib/agent/crypto/keystore/function.dart @@ -322,7 +322,7 @@ Future encryptMessage({ return EncryptMessageResponse( content: '$encryptedMessage?iv=$ivBase64', tags: [ - ['p', theirPublicKey.toRaw().toHex()] + ['p', theirPublicKey.toRaw().toHex()], ], kind: 4, createdAt: (DateTime.now().millisecondsSinceEpoch / 1000).floor(), @@ -441,7 +441,7 @@ class EncryptMessageResponse { 'tags': tags, 'kind': kind, 'created_at': createdAt, - 'pubkey': pubKey + 'pubkey': pubKey, }; } diff --git a/lib/agent/crypto/keystore/key_derivator.dart b/lib/agent/crypto/keystore/key_derivator.dart index a9b9f25a..d36b7551 100644 --- a/lib/agent/crypto/keystore/key_derivator.dart +++ b/lib/agent/crypto/keystore/key_derivator.dart @@ -35,7 +35,7 @@ class _PBDKDF2KeyDerivator extends KeyDerivator { 'c': iterations, 'dklen': dklen, 'prf': 'hmac-sha256', - 'salt': salt.toHex() + 'salt': salt.toHex(), }; } diff --git a/lib/agent/polling/strategy.dart b/lib/agent/polling/strategy.dart index b9f94bae..61c4d08a 100644 --- a/lib/agent/polling/strategy.dart +++ b/lib/agent/polling/strategy.dart @@ -19,7 +19,7 @@ PollStrategy defaultStrategy() { return chain([ conditionalDelay(once(), 1000), backoff(1000, 1.2), - timeout(5 * 60 * 1000) + timeout(5 * 60 * 1000), ]); } diff --git a/lib/archiver/encoder.dart b/lib/archiver/encoder.dart index b46db518..66f27a99 100644 --- a/lib/archiver/encoder.dart +++ b/lib/archiver/encoder.dart @@ -50,7 +50,7 @@ class SigningBlockEncoder extends ZipEncoder { messages: [message], signatures: [signature], publicKeys: [publicKey], - ) + ), ], ); @@ -159,9 +159,9 @@ class SingingBlockZipFileEncoder extends ZipFileEncoder { } @override - void close() { + Future close() async { _encoder.writeBlock(_output); _encoder.endEncode(); - _output.close(); + await _output.close(); } } diff --git a/lib/auth_client/auth_client.dart b/lib/auth_client/auth_client.dart index 680f5eaf..ce73629d 100644 --- a/lib/auth_client/auth_client.dart +++ b/lib/auth_client/auth_client.dart @@ -278,7 +278,7 @@ class AuthClient { 'sessionPublicKey': key != null ? (key as SignIdentity).getPublicKey().toDer().toHex() : null, - 'canisterId': options?.canisterId + 'canisterId': options?.canisterId, }, ); return AuthPayload(identityProviderUrl.toString(), scheme); diff --git a/lib/authentication/authentication.dart b/lib/authentication/authentication.dart index a1d3e32d..25d31a7b 100644 --- a/lib/authentication/authentication.dart +++ b/lib/authentication/authentication.dart @@ -22,9 +22,8 @@ class CreateUrlOptions { final PublicKey publicKey; /// The scope of the delegation. This must contain at least one key and - /// a maximum of four. This is validated in - /// {@link createAuthenticationRequestUrl} but also will be validated as part - /// of the identity provider. + /// a maximum of four. This is validated in [createAuthenticationRequestUrl] + /// but also will be validated as part of the identity provider. final List scope; /// The URI to redirect to, after authentication. By default, @@ -66,7 +65,7 @@ Uri createAuthenticationRequestUrl(CreateUrlOptions options) { .map((p) => p.toString()) .join(' '), ), - const MapEntry('state', '') + const MapEntry('state', ''), ]); return url; diff --git a/lib/bridge/wasm_interop.dart b/lib/bridge/wasm_interop.dart index ef7c8ad3..326adaaa 100644 --- a/lib/bridge/wasm_interop.dart +++ b/lib/bridge/wasm_interop.dart @@ -594,7 +594,7 @@ const _importExportKindMap = { 'function': ImportExportKind.function, 'global': ImportExportKind.global, 'memory': ImportExportKind.memory, - 'table': ImportExportKind.table + 'table': ImportExportKind.table, }; @JS() diff --git a/lib/candid/idl.dart b/lib/candid/idl.dart index f575e768..f154dd36 100644 --- a/lib/candid/idl.dart +++ b/lib/candid/idl.dart @@ -750,7 +750,7 @@ class VecClass extends ConstructType> { final len = lebEncode(x.length); return u8aConcat([ len, - ...x.map((dynamic d) => tryToJson(_type, d) ?? _type.encodeValue(d)) + ...x.map((dynamic d) => tryToJson(_type, d) ?? _type.encodeValue(d)), ]); } @@ -816,7 +816,7 @@ class OptClass extends ConstructType { final val = x[0]; return u8aConcat([ Uint8List.fromList([1]), - tryToJson(_type, val) ?? _type.encodeValue(val) + tryToJson(_type, val) ?? _type.encodeValue(val), ]); } @@ -931,7 +931,7 @@ class RecordClass extends ConstructType { final fields = _fields.map( (entry) => u8aConcat([ lebEncode(idlLabelToId(entry.key)), - entry.value.encodeType(typeTable) + entry.value.encodeType(typeTable), ]), ); typeTable.add(this, u8aConcat([opCode, len, u8aConcat(fields.toList())])); @@ -1051,7 +1051,7 @@ class TupleClass extends ConstructType { final fields = _fields.map( (entry) => u8aConcat([ lebEncode(idlLabelToId(entry.key)), - entry.value.encodeType(typeTable) + entry.value.encodeType(typeTable), ]), ); typeTable.add(this, u8aConcat([opCode, len, u8aConcat(fields.toList())])); @@ -1171,7 +1171,7 @@ class VariantClass extends ConstructType> { final fields = _fields.map( (entry) => u8aConcat([ lebEncode(idlLabelToId(entry.key)), - entry.value.encodeType(typeTable) + entry.value.encodeType(typeTable), ]), ); typeTable.add(this, u8aConcat([opCode, len, ...fields])); @@ -1353,7 +1353,7 @@ class PrincipalClass extends PrimitiveType { return u8aConcat([ Uint8List.fromList([1]), len, - buf + buf, ]); } diff --git a/lib/identity/der.dart b/lib/identity/der.dart index 65e2f3e9..63bdedbc 100644 --- a/lib/identity/der.dart +++ b/lib/identity/der.dart @@ -141,7 +141,7 @@ final oidP256 = Uint8List.fromList([ 0x03, 0x01, 0x07, - ] + ], ]); /// Wraps the given [payload] in a DER encoding tagged with the given encoded diff --git a/lib/utils/bech32.dart b/lib/utils/bech32.dart index 57a06495..332ba0a7 100644 --- a/lib/utils/bech32.dart +++ b/lib/utils/bech32.dart @@ -296,7 +296,7 @@ const List charset = [ 'u', 'a', '7', - 'l' + 'l', ]; // @formatter:on @@ -306,7 +306,7 @@ const List generator = [ 0x26508e6d, 0x1ea119fa, 0x3d4233dd, - 0x2a1462b3 + 0x2a1462b3, ]; // @formatter:on diff --git a/lib/wallet/ledger.dart b/lib/wallet/ledger.dart index 50de92f3..dd26a8cd 100644 --- a/lib/wallet/ledger.dart +++ b/lib/wallet/ledger.dart @@ -272,7 +272,7 @@ class SendArgs { 'memo': memo, 'from_subaccount': fromSubAccount != null ? [fromSubAccount] : [], 'created_at_time': createdAtTime != null ? [createdAtTime!.toJson()] : [], - 'amount': amount.toJson() + 'amount': amount.toJson(), }..removeWhere((key, value) => value == null); } } @@ -363,7 +363,7 @@ class TransferArgs { 'memo': memo, 'from_subaccount': fromSubAccount != null ? [fromSubAccount] : [], 'created_at_time': createdAtTime != null ? [createdAtTime!.toJson()] : [], - 'amount': amount.toJson() + 'amount': amount.toJson(), }..removeWhere((key, value) => value == null); } } @@ -412,7 +412,7 @@ class TransferError { 'BadFee': badFee, 'TxDuplicate': txDuplicate, 'InsufficientFunds': insufficientFunds, - 'TxCreatedInFuture': txCreatedInFuture + 'TxCreatedInFuture': txCreatedInFuture, }..removeWhere((key, value) => value == null || value == false); if (res['TxCreatedInFuture'] != null && res['TxCreatedInFuture'] == true) { res.update('TxCreatedInFuture', (value) => null); @@ -597,7 +597,7 @@ class Ledger { ? null : { 'timestamp_nanos': - sendOpts?.createAtTime?.millisecondsSinceEpoch.toBn() + sendOpts?.createAtTime?.millisecondsSinceEpoch.toBn(), }, }; final res = await ledgerInstance.agent.actor!.getFunc( diff --git a/lib/wallet/rosetta.dart b/lib/wallet/rosetta.dart index 51986cdd..3be0c6dd 100644 --- a/lib/wallet/rosetta.dart +++ b/lib/wallet/rosetta.dart @@ -131,7 +131,7 @@ class RosettaApi { Future getNetworkIdentifier() async { final networkList = await networksList(); - networkIdentifier = (networkList.networkIdentifiers).singleWhere( + networkIdentifier = networkList.networkIdentifiers.singleWhere( (rosetta.NetworkIdentifier id) => id.blockchain == 'Internet Computer', orElse: () => throw StateError('No identifier found.'), ); @@ -329,7 +329,7 @@ class RosettaApi { assert(networkIdentifier != null, 'Cannot get networkIdentifier.'); final result = await request('/account/balance', { 'network_identifier': networkIdentifier, - 'account_identifier': {'address': accountAddress} + 'account_identifier': {'address': accountAddress}, }); return rosetta.AccountBalanceResponse.fromJson(result); } @@ -343,7 +343,7 @@ class RosettaApi { assert(networkIdentifier != null, 'Cannot get networkIdentifier.'); final result = await request('/block', { 'network_identifier': networkIdentifier, - 'block_identifier': {'index': blockIndex} + 'block_identifier': {'index': blockIndex}, }); return rosetta.BlockResponse.fromJson(result); } @@ -359,7 +359,7 @@ class RosettaApi { assert(networkIdentifier != null, 'Cannot get networkIdentifier.'); final result = await request('/search/transactions', { 'network_identifier': networkIdentifier, - 'account_identifier': {'address': accountAddress} + 'account_identifier': {'address': accountAddress}, }); return rosetta.SearchTransactionsResponse.fromJson(result); } @@ -374,7 +374,7 @@ class RosettaApi { assert(networkIdentifier != null, 'Cannot get networkIdentifier.'); final result = await request('/search/transactions', { 'network_identifier': networkIdentifier, - 'transaction_identifier': {'hash': transactionHash} + 'transaction_identifier': {'hash': transactionHash}, }); return rosetta.SearchTransactionsResponse.fromJson(result); } diff --git a/pubspec.yaml b/pubspec.yaml index f6c56179..558edc95 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -4,14 +4,14 @@ description: | a plugin package for dart and flutter apps. Developers can build ones to interact with Dfinity's blockchain directly. repository: https://github.com/AstroxNetwork/agent_dart -version: 1.0.0-dev.22 +version: 1.0.0-dev.23 environment: sdk: '>=3.0.0 <4.0.0' flutter: '>=3.10.0' dependencies: - archive: ^3.3.8 + archive: ^3.5.0 args: ^2.3.1 bip32: ^2.0.0 bip39: ^1.0.6 @@ -25,7 +25,7 @@ dependencies: sdk: flutter flutter_rust_bridge: ^1.82.6 http: ^1.0.0 - js: ^0.6.4 + js: '>=0.6.0 <0.8.0' meta: ^1.7.0 path: ^1.8.1 pinenacl: ^0.5.1 @@ -39,7 +39,7 @@ dependencies: dev_dependencies: build_runner: ^2.1.11 - lints: ^2.0.1 + lints: any flutter_test: sdk: flutter ffigen: '>=8.0.0 <10.0.0' diff --git a/test/agent/certificate.dart b/test/agent/certificate.dart index 87ab36dc..02b9c7da 100644 --- a/test/agent/certificate.dart +++ b/test/agent/certificate.dart @@ -36,21 +36,21 @@ void hashTest() { [ 2, label('x'), - [3, label('hello')] + [3, label('hello')], ], - [0] + [0], ], [ 2, label('y'), - [3, label('world')] + [3, label('world')], ] ], ], [ 2, label('b'), - [3, label('good')] + [3, label('good')], ], ], [ @@ -58,12 +58,12 @@ void hashTest() { [ 2, label('c'), - [0] + [0], ], [ 2, label('d'), - [3, label('morning')] + [3, label('morning')], ] ], ]; @@ -97,12 +97,12 @@ void hashTest() { 4, pruned( '1b4feff9bef8131788b0c9dc6dbad6e81e524249c879e9f10f71ce3749f5a638', - ) + ), ], [ 2, label('y'), - [3, label('world')] + [3, label('world')], ], ], ], @@ -113,7 +113,7 @@ void hashTest() { 4, pruned( '7b32ac0c6ba8ce35ac82c255fc7906f7fc130dab2a090f80fe12f9c2cae83ba6', - ) + ), ], ], ], @@ -123,12 +123,12 @@ void hashTest() { 4, pruned( 'ec8324b8a1f1ac16bd2e806edba78006479c9877fed4eb464a25485465af601d', - ) + ), ], [ 2, label('d'), - [3, label('morning')] + [3, label('morning')], ], ], ]; @@ -155,12 +155,12 @@ void hashTest() { 4, pruned( '1b4feff9bef8131788b0c9dc6dbad6e81e524249c879e9f10f71ce3749f5a638', - ) + ), ], [ 2, label('y'), - [3, label('world')] + [3, label('world')], ], ], ], @@ -171,7 +171,7 @@ void hashTest() { 4, pruned( '7b32ac0c6ba8ce35ac82c255fc7906f7fc130dab2a090f80fe12f9c2cae83ba6', - ) + ), ], ], ], @@ -181,12 +181,12 @@ void hashTest() { 4, pruned( 'ec8324b8a1f1ac16bd2e806edba78006479c9877fed4eb464a25485465af601d', - ) + ), ], [ 2, label('d'), - [3, label('morning')] + [3, label('morning')], ], ], ]; @@ -194,7 +194,7 @@ void hashTest() { lookupPath( [ 'a'.plainToU8a(useDartEncode: true), - 'a'.plainToU8a(useDartEncode: true) + 'a'.plainToU8a(useDartEncode: true), ], tree, ), @@ -205,7 +205,7 @@ void hashTest() { lookupPath( [ 'a'.plainToU8a(useDartEncode: true), - 'y'.plainToU8a(useDartEncode: true) + 'y'.plainToU8a(useDartEncode: true), ], tree, ), diff --git a/test/candid/idl.dart b/test/candid/idl.dart index b6c07abd..35a59cb1 100644 --- a/test/candid/idl.dart +++ b/test/candid/idl.dart @@ -269,9 +269,9 @@ void idlTest() { ); expect( () => IDL.encode([ - IDL.Tuple([IDL.Int, IDL.Text]) + IDL.Tuple([IDL.Int, IDL.Text]), ], [ - [0] + [0], ]), throwsA(isError()), ); @@ -302,7 +302,7 @@ void idlTest() { BigInt.from(0), BigInt.from(1), BigInt.from(1) << 60, - BigInt.from(13) + BigInt.from(13), ], '4449444c016d780100040000000000000000010000000000000000000000000000100d00000000000000', 'Array of Nat64s', @@ -329,9 +329,9 @@ void idlTest() { ); expect( () => IDL.encode([ - IDL.Vec(IDL.Int) + IDL.Vec(IDL.Int), ], [ - ['fail'] + ['fail'], ]), throwsA(isError()), ); @@ -342,7 +342,7 @@ void idlTest() { testArg( IDL.Vec(IDL.Tuple([IDL.Int, IDL.Text])), [ - [BigInt.from(42), 'text'] + [BigInt.from(42), 'text'], ], '4449444c026c02007c01716d000101012a0474657874', 'Arr of Tuple', @@ -353,14 +353,14 @@ void idlTest() { IDL.Tuple([ IDL.Tuple([ IDL.Tuple([ - IDL.Tuple([IDL.Null]) - ]) - ]) + IDL.Tuple([IDL.Null]), + ]), + ]), ]), [ [ [ - [null] + [null], ] ] ], @@ -374,9 +374,9 @@ void idlTest() { testArg(IDL.Record({}), {}, '4449444c016c000100', 'Empty record'); expect( () => IDL.encode([ - IDL.Record({'a': IDL.Text}) + IDL.Record({'a': IDL.Text}), ], [ - {'b': 'b'} + {'b': 'b'}, ]), throwsA(isError("Record is missing the key 'a'.")), ); @@ -400,13 +400,13 @@ void idlTest() { final foobar = FooBar.fromJson({'foo': '💩', 'bar': BigInt.from(42)}); final encode = IDL.encode([ - IDL.Opt(IDL.Record({'foo': IDL.Text, 'bar': IDL.Int})) + IDL.Opt(IDL.Record({'foo': IDL.Text, 'bar': IDL.Int})), ], [ - [foobar] + [foobar], ]); final decode = IDL.decode( [ - IDL.Opt(IDL.Record({'foo': IDL.Text, 'bar': IDL.Int})) + IDL.Opt(IDL.Record({'foo': IDL.Text, 'bar': IDL.Int})), ], encode, ); @@ -434,7 +434,7 @@ void idlTest() { 'foo': IDL.Int32, 'bar': recordType, 'baz': recordType, - 'bib': recordType + 'bib': recordType, }), {'foo': 42, 'bar': recordValue, 'baz': recordValue, 'bib': recordValue}, '4449444c026c02d3e3aa027e868eb702756c04d3e3aa0200dbe3aa0200bbf1aa0200868eb702750101012a000000012a000000012a0000002a000000', @@ -442,10 +442,10 @@ void idlTest() { ); testDecode( IDL.Record({ - 'baz': IDL.Record({'foo': IDL.Int32}) + 'baz': IDL.Record({'foo': IDL.Int32}), }), { - 'baz': {'foo': 42} + 'baz': {'foo': 42}, }, '4449444c026c02d3e3aa027e868eb702756c04d3e3aa0200dbe3aa0200bbf1aa0200868eb702750101012a000000012a000000012a0000002a000000', 'skip nested fields', @@ -470,11 +470,11 @@ void idlTest() { testArg( IDL.Tuple([ IDL.Tuple([IDL.Int8, IDL.Bool]), - IDL.Record({'_0_': IDL.Int8, '_1_': IDL.Bool}) + IDL.Record({'_0_': IDL.Int8, '_1_': IDL.Bool}), ]), [ [42, true], - {'_0_': 42, '_1_': true} + {'_0_': 42, '_1_': true}, ], '4449444c026c020077017e6c020000010001012a012a01', 'Tuple and Record', @@ -551,7 +551,7 @@ void idlTest() { // Service testArg( IDL.Service({ - 'foo': IDL.Func([IDL.Text], [IDL.Nat], []) + 'foo': IDL.Func([IDL.Text], [IDL.Nat], []), }), Principal.fromText('w7x7r-cok77-xa'), '4449444c026a0171017d00690103666f6f0001010103caffee', @@ -559,7 +559,7 @@ void idlTest() { ); testArg( IDL.Service({ - 'foo': IDL.Func([IDL.Text], [IDL.Nat], ['query']) + 'foo': IDL.Func([IDL.Text], [IDL.Nat], ['query']), }), Principal.fromText('w7x7r-cok77-xa'), '4449444c026a0171017d0101690103666f6f0001010103caffee', @@ -576,7 +576,7 @@ void idlTest() { ); testArg( IDL.Service({ - 'foo': IDL.Func([IDL.Text], [IDL.Nat], ['composite_query']) + 'foo': IDL.Func([IDL.Text], [IDL.Nat], ['composite_query']), }), Principal.fromText('w7x7r-cok77-xa'), '4449444c026a0171017d0103690103666f6f0001010103caffee', @@ -606,9 +606,9 @@ void idlTest() { ); expect( () => IDL.encode([ - result + result, ], [ - {'ok': 'ok', 'err': 'err'} + {'ok': 'ok', 'err': 'err'}, ]), throwsA(isError()), ); @@ -630,9 +630,9 @@ void idlTest() { ); expect( () => IDL.encode([ - IDL.Variant({'ok': IDL.Text, 'err': IDL.Empty}) + IDL.Variant({'ok': IDL.Text, 'err': IDL.Empty}), ], [ - {'err': 'uhoh'} + {'err': 'uhoh'}, ]), throwsA(isError()), ); @@ -648,7 +648,7 @@ void idlTest() { testArg( IDL.Opt(IDL.Opt(IDL.Nat)), [ - [BigInt.from(1)] + [BigInt.from(1)], ], '4449444c026e7d6e000101010101', 'Nested option', @@ -656,7 +656,7 @@ void idlTest() { testArg( IDL.Opt(IDL.Opt(IDL.Null)), [ - [null] + [null], ], '4449444c026e7f6e0001010101', 'Null option', @@ -668,7 +668,7 @@ void idlTest() { IDL.Vec(IDL.Int), IDL.Vec(IDL.Nat), IDL.Vec(IDL.Int), - IDL.Vec(IDL.Nat) + IDL.Vec(IDL.Nat), ]), [[], [], [], []], '4449444c036d7c6d7d6c040000010102000301010200000000', @@ -697,8 +697,8 @@ void idlTest() { { 'head': BigInt.from(1), 'tail': [ - {'head': BigInt.from(2), 'tail': []} - ] + {'head': BigInt.from(2), 'tail': []}, + ], } ], '4449444c026e016c02a0d2aca8047c90eddae7040001000101010200', @@ -724,8 +724,8 @@ void idlTest() { { 'head': BigInt.from(1), 'tail': [ - {'head': BigInt.from(2), 'tail': []} - ] + {'head': BigInt.from(2), 'tail': []}, + ], } ], '4449444c026e016c02a0d2aca8047c90eddae7040001000101010200', @@ -741,7 +741,7 @@ void idlTest() { [ BigInt.from(42), ['test'], - {'ok': 'good'} + {'ok': 'good'}, ], '4449444c026e716b029cc20171e58eb40271037d00012a0104746573740004676f6f64', 'Multiple arguments', diff --git a/test/utils/is.dart b/test/utils/is.dart index 8955e2a3..b7ac217d 100644 --- a/test/utils/is.dart +++ b/test/utils/is.dart @@ -30,7 +30,7 @@ void main() { test('isJsonObject', () { const jsonObject = { 'Test': '1234', - 'NestedTest': {'Test': '5678'} + 'NestedTest': {'Test': '5678'}, }; expect(isJsonObject('{}'), true); // true expect(isJsonObject(jsonEncode(jsonObject)), true); // true