Bump dev (w/ eslint 8) (#4070)

* Bump dev (w/ eslint 8)

* Additional linting

* Additional

* More lint fixes

* Last batch

* Additional

* Cleanups
This commit is contained in:
Jaco
2021-10-17 14:49:26 +03:00
committed by GitHub
parent 806fda67e9
commit 5eb3534d8e
46 changed files with 328 additions and 307 deletions
+4 -4
View File
@@ -1,7 +1,7 @@
// Copyright 2017-2021 @polkadot/api-contract authors & contributors
// SPDX-License-Identifier: Apache-2.0
import type { Registry } from '@polkadot/types/types';
import type { AnyJson, Registry } from '@polkadot/types/types';
import fs from 'fs';
import path from 'path';
@@ -51,7 +51,7 @@ describe('Abi', (): void => {
it(`initializes from a contract ABI (${abiName})`, (): void => {
try {
const messageIds = (abi.V1 ? abi.V1 : abi).spec.messages.map(({ name }) => Array.isArray(name) ? name[0] : name);
const inkAbi = new Abi(abis[abiName]);
const inkAbi = new Abi(abis[abiName] as AnyJson);
expect(inkAbi.messages.map(({ identifier }) => identifier)).toEqual(messageIds);
} catch (error) {
@@ -66,7 +66,7 @@ describe('Abi', (): void => {
describe('TypeDef', (): void => {
Object.keys(abis).forEach((abiName) => {
it(`initializes from a contract ABI (${abiName})`, (): void => {
const abi = new Abi(abis[abiName]);
const abi = new Abi(abis[abiName] as AnyJson);
const json = stringifyJson(abi.registry);
const cmpPath = path.join(__dirname, `../../test/compare/${abiName}.test.json`);
@@ -88,7 +88,7 @@ describe('Abi', (): void => {
it('has the correct hash for the source', (): void => {
const bundle = abis.ink_v0_flipperBundle as JSONAbi;
const abi = new Abi(bundle as any);
const abi = new Abi(bundle as unknown as AnyJson);
// manual
expect(bundle.source.hash).toEqual(blake2AsHex(bundle.source.wasm));
+6 -6
View File
@@ -173,7 +173,7 @@ export class Abi {
throw error;
}
});
}
};
#createEvent = (spec: ContractEventSpec, index: number): AbiEvent => {
const args = this.#createArgs(spec.args, spec);
@@ -189,7 +189,7 @@ export class Abi {
};
return event;
}
};
#createMessage = (spec: ContractMessageSpec | ContractConstructorSpec, index: number, add: Partial<AbiMessage> = {}): AbiMessage => {
const args = this.#createArgs(spec.args, spec);
@@ -211,7 +211,7 @@ export class Abi {
};
return message;
}
};
#decodeArgs = (args: AbiParam[], data: Uint8Array): Codec[] => {
// for decoding we expect the input to be just the arg data, no selectors
@@ -225,7 +225,7 @@ export class Abi {
return value;
});
}
};
#decodeMessage = (type: 'constructor' | 'message', list: AbiMessage[], data: Uint8Array): DecodedMessage => {
const [, trimmed] = compactStripLength(data);
@@ -235,7 +235,7 @@ export class Abi {
assert(message, `Unable to find ${type} with selector ${u8aToHex(selector)}`);
return message.fromU8a(trimmed.subarray(4));
}
};
#encodeArgs = ({ name, selector }: ContractMessageSpec | ContractConstructorSpec, args: AbiParam[], data: unknown[]): Uint8Array => {
assert(data.length === args.length, () => `Expected ${args.length} arguments to contract message '${name.toString()}', found ${data.length}`);
@@ -248,5 +248,5 @@ export class Abi {
)
)
);
}
};
}
+1 -1
View File
@@ -66,5 +66,5 @@ export class Blueprint<ApiType extends ApiTypes> extends Base<ApiType> {
new Contract<ApiType>(this.api, this.abi, record.event.data[1] as AccountId, this._decorateMethod)
))
);
}
};
}
+5 -3
View File
@@ -1,6 +1,8 @@
// Copyright 2017-2021 @polkadot/api-contract authors & contributors
// SPDX-License-Identifier: Apache-2.0
import type { AnyJson } from '@polkadot/types/types';
import fs from 'fs';
import path from 'path';
@@ -17,19 +19,19 @@ const v0wasmFlipper = fs.readFileSync(path.join(__dirname, '../../test/contracts
describe('Code', (): void => {
it('can construct with an individual ABI/WASM combo', (): void => {
expect(
() => new Code(mockApi, v0abiFlipper, v0wasmFlipper, decorateMethodPromise)
() => new Code(mockApi, v0abiFlipper as AnyJson, v0wasmFlipper, decorateMethodPromise)
).not.toThrow();
});
it('can construct with an .contract ABI (v0)', (): void => {
expect(
() => new Code(mockApi, v0contractFlipper, null, decorateMethodPromise)
() => new Code(mockApi, v0contractFlipper as AnyJson, null, decorateMethodPromise)
).not.toThrow();
});
it.only('can construct with an .contract ABI (v1)', (): void => {
expect(
() => new Code(mockApi, v1contractFlipper, null, decorateMethodPromise)
() => new Code(mockApi, v1contractFlipper as AnyJson, null, decorateMethodPromise)
).not.toThrow();
});
});
+1 -1
View File
@@ -76,5 +76,5 @@ export class Code<ApiType extends ApiTypes> extends Base<ApiType> {
[])
) || []))
);
}
};
}
+3 -3
View File
@@ -100,7 +100,7 @@ export class Contract<ApiType extends ApiTypes> extends Base<ApiType> {
: this.api.consts.system.maximumBlockWeight as Weight
).muln(64).div(BN_HUNDRED)
: gasLimit;
}
};
#exec = (messageOrId: AbiMessage | string | number, { gasLimit = BN_ZERO, value = BN_ZERO }: ContractOptions, params: unknown[]): SubmittableExtrinsic<ApiType> => {
return this.api.tx.contracts
@@ -126,7 +126,7 @@ export class Contract<ApiType extends ApiTypes> extends Base<ApiType> {
.filter((decoded): decoded is DecodedEvent => !!decoded)
))
);
}
};
#read = (messageOrId: AbiMessage | string | number, { gasLimit = BN_ZERO, value = BN_ZERO }: ContractOptions, params: unknown[]): ContractCallSend<ApiType> => {
assert(this.hasRpcContractsCall, ERROR_NO_CALL);
@@ -159,5 +159,5 @@ export class Contract<ApiType extends ApiTypes> extends Base<ApiType> {
)
)
};
}
};
}
@@ -3,6 +3,8 @@
// Simple non-runnable checks to test type definitions in the editor itself
import type { AnyJson } from '@polkadot/types/types';
import { ApiPromise } from '@polkadot/api';
import { createTestPairs, TestKeyringMap } from '@polkadot/keyring/testingPairs';
@@ -10,7 +12,7 @@ import abiIncrementer from '../test/contracts/ink/incrementer.json';
import { BlueprintPromise, ContractPromise } from '.';
async function checkBlueprint (api: ApiPromise, pairs: TestKeyringMap): Promise<void> {
const blueprint = new BlueprintPromise(api, abiIncrementer, '0x1234');
const blueprint = new BlueprintPromise(api, abiIncrementer as AnyJson, '0x1234');
// new style
await blueprint.tx.new({ gasLimit: 456, salt: '0x1234', value: 123 }, 42).signAndSend(pairs.bob);
@@ -21,7 +23,7 @@ async function checkBlueprint (api: ApiPromise, pairs: TestKeyringMap): Promise<
}
async function checkContract (api: ApiPromise, pairs: TestKeyringMap): Promise<void> {
const contract = new ContractPromise(api, abiIncrementer, '0x1234');
const contract = new ContractPromise(api, abiIncrementer as AnyJson, '0x1234');
// queries
await contract.query.get(pairs.alice.address, {});