From d942c779f268cf1c7ab22fe0bf1e0113dfd300a7 Mon Sep 17 00:00:00 2001 From: dafuga Date: Wed, 30 Aug 2023 23:47:42 -0700 Subject: [PATCH] style: linted --- src/account.ts | 56 ++++++------- src/contracts/eosio.ts | 1 - src/kit.ts | 3 +- test/tests/account.ts | 163 +++++++++++++++++++------------------- test/tests/kit.ts | 59 +++++++------- test/tests/permissions.ts | 5 +- test/utils/helpers.ts | 4 +- test/utils/mock-data.ts | 2 +- 8 files changed, 145 insertions(+), 148 deletions(-) diff --git a/src/account.ts b/src/account.ts index 8fcf175..dbc8e4c 100644 --- a/src/account.ts +++ b/src/account.ts @@ -31,9 +31,9 @@ export class Account { readonly eosioContract: Eosio.Contract readonly client: APIClient - constructor({ accountData, client }: AccountArgs) { + constructor({accountData, client}: AccountArgs) { this.account_data = accountData - this.eosioContract = new Eosio.Contract({ client }) + this.eosioContract = new Eosio.Contract({client}) this.client = client } @@ -42,8 +42,8 @@ export class Account { } getPermission(permissionName: NameType): Permission { - const permissionObject = this.account_data.permissions.find( - (permission) => permission.perm_name.equals(permissionName) + const permissionObject = this.account_data.permissions.find((permission) => + permission.perm_name.equals(permissionName) ) if (!permissionObject) { @@ -57,7 +57,7 @@ export class Account { parent: permissionObject.parent, permission: permissionObject.perm_name, auth: Authority.from(permissionObject.required_auth), - authorized_by: "............1", + authorized_by: '............1', }) } @@ -67,58 +67,52 @@ export class Account { removePermission(permissionName: NameType): Action { return this.eosioContract.action('deleteauth', { - account: "............1", - authorized_by: "............1", + account: '............1', + authorized_by: '............1', permission: permissionName, }) } buyRam(amount: AssetType): Action { return this.eosioContract.action('buyram', { - payer: "............1", - receiver: "............1", + payer: '............1', + receiver: '............1', quant: amount, }) } buyRamBytes(bytes: number): Action { return this.eosioContract.action('buyrambytes', { - payer: "............1", - receiver: "............1", + payer: '............1', + receiver: '............1', bytes, }) } sellRam(bytes: number): Action { return this.eosioContract.action('sellram', { - account: "............1", + account: '............1', bytes, }) } delegateResources(cpu: AssetType, net: AssetType): Action { - return this.eosioContract.action( - 'delegatebw', - { - from: "............1", - receiver: "............1", - stake_cpu_quantity: cpu, - stake_net_quantity: net, - transfer: false, - } - ) + return this.eosioContract.action('delegatebw', { + from: '............1', + receiver: '............1', + stake_cpu_quantity: cpu, + stake_net_quantity: net, + transfer: false, + }) } undelegateResources(cpu: AssetType, net: AssetType): Action { - return this.eosioContract.action( - 'undelegatebw', - { - from: "............1", - receiver: "............1", - unstake_cpu_quantity: cpu, - unstake_net_quantity: net, - } - ) + return this.eosioContract.action('undelegatebw', { + from: '............1', + receiver: '............1', + unstake_cpu_quantity: cpu, + unstake_net_quantity: net, + }) } getResources(): Resources { diff --git a/src/contracts/eosio.ts b/src/contracts/eosio.ts index c15c6bf..126ffbd 100644 --- a/src/contracts/eosio.ts +++ b/src/contracts/eosio.ts @@ -1536,4 +1536,3 @@ export namespace Eosio { } } export default Eosio - diff --git a/src/kit.ts b/src/kit.ts index 738574b..e618c4c 100644 --- a/src/kit.ts +++ b/src/kit.ts @@ -1,4 +1,3 @@ - import {APIClient, Name, NameType} from '@wharfkit/antelope' import {Account} from './account' @@ -39,4 +38,4 @@ export class AccountKit { client: this.client, }) } -} \ No newline at end of file +} diff --git a/test/tests/account.ts b/test/tests/account.ts index 4603fb4..d41ff7d 100644 --- a/test/tests/account.ts +++ b/test/tests/account.ts @@ -4,8 +4,8 @@ import {API, APIClient} from '@wharfkit/antelope' import {Account, AccountKit, Permission} from '../../src' import {MockProvider} from '../utils/mock-provider' import {deserializedMockAccountObject} from '../utils/mock-data' -import { Name } from '@greymass/eosio' -import { deserialize } from 'test/utils/helpers' +import {Name} from '@greymass/eosio' +import {deserialize} from 'test/utils/helpers' const eosApiClient = new APIClient({ provider: new MockProvider('https://eos.greymass.com'), @@ -15,11 +15,14 @@ suite('Account', function () { let testAccount: Account this.beforeAll(async function () { - testAccount = await (new AccountKit({client: eosApiClient})).load('teamgreymass') + testAccount = await new AccountKit({client: eosApiClient}).load('teamgreymass') }) test('construct', function () { - const account = new Account({ client: eosApiClient, accountData: deserializedMockAccountObject}) + const account = new Account({ + client: eosApiClient, + accountData: deserializedMockAccountObject, + }) assert.instanceOf(account, Account) }) @@ -69,11 +72,11 @@ suite('Account', function () { suite('updatePermission', () => { test('returns current Action', () => { - const permission = new Permission("permission", { - account: "............1", - parent: "............1", - permission: "............1", - authorized_by: "............1", + const permission = new Permission('permission', { + account: '............1', + parent: '............1', + permission: '............1', + authorized_by: '............1', auth: { accounts: [], keys: [ @@ -85,123 +88,123 @@ suite('Account', function () { threshold: 1, waits: [], }, - }); - const action = testAccount.updatePermission(permission); + }) + const action = testAccount.updatePermission(permission) assert.deepEqual(deserialize(action), { - account: "eosio", + account: 'eosio', authorization: [ { - actor: "............1", - permission: "............2" - } + actor: '............1', + permission: '............2', + }, ], - data: "01000000000000000100000000000000010000000000000001000000010002c0ded2bc1f1305fb0faac5e6c03ee3a1924234985427b6167ca569d13df435cf010000000100000000000000", - name: "updateauth" - }); - }); - }); + data: '01000000000000000100000000000000010000000000000001000000010002c0ded2bc1f1305fb0faac5e6c03ee3a1924234985427b6167ca569d13df435cf010000000100000000000000', + name: 'updateauth', + }) + }) + }) suite('removePermission', () => { test('returns current Action', () => { - const action = testAccount.removePermission("someName"); + const action = testAccount.removePermission('someName') assert.deepEqual(deserialize(action), { - account: "eosio", + account: 'eosio', authorization: [ { - actor: "............1", - permission: "............2" - } + actor: '............1', + permission: '............2', + }, ], - data: "01000000000000000000004a1aa024c50100000000000000", - name: "deleteauth" - }); - }); - }); + data: '01000000000000000000004a1aa024c50100000000000000', + name: 'deleteauth', + }) + }) + }) suite('buyRam', () => { test('returns current Action', () => { - const action = testAccount.buyRam("1.0000 EOS"); + const action = testAccount.buyRam('1.0000 EOS') assert.deepEqual(deserialize(action), { - account: "eosio", + account: 'eosio', authorization: [ { - "actor": "............1", - "permission": "............2" - } + actor: '............1', + permission: '............2', + }, ], - data: "01000000000000000100000000000000102700000000000004454f5300000000", - name: "buyram" - }); - }); - }); + data: '01000000000000000100000000000000102700000000000004454f5300000000', + name: 'buyram', + }) + }) + }) suite('buyRamBytes', () => { test('returns current Action', () => { - const action = testAccount.buyRamBytes(1024); + const action = testAccount.buyRamBytes(1024) assert.deepEqual(deserialize(action), { - account: "eosio", + account: 'eosio', authorization: [ { - actor: "............1", - permission: "............2" - } + actor: '............1', + permission: '............2', + }, ], - data: "0100000000000000010000000000000000040000", - name: "buyrambytes" - }); - }); - }); + data: '0100000000000000010000000000000000040000', + name: 'buyrambytes', + }) + }) + }) suite('sellRam', () => { test('returns current Action', () => { - const action = testAccount.sellRam(1024); + const action = testAccount.sellRam(1024) assert.deepEqual(deserialize(action), { - account: "eosio", + account: 'eosio', authorization: [ { - actor: "............1", - permission: "............2" - } + actor: '............1', + permission: '............2', + }, ], - data: "01000000000000000004000000000000", - name: "sellram" - }); - }); - }); + data: '01000000000000000004000000000000', + name: 'sellram', + }) + }) + }) suite('delegateResources', () => { test('returns current Action', () => { - const action = testAccount.delegateResources("1.0000 EOS", "0.5000 EOS"); + const action = testAccount.delegateResources('1.0000 EOS', '0.5000 EOS') assert.deepEqual(deserialize(action), { - account: "eosio", + account: 'eosio', authorization: [ { - actor: "............1", - permission: "............2" - } + actor: '............1', + permission: '............2', + }, ], - data: "01000000000000000100000000000000881300000000000004454f5300000000102700000000000004454f530000000000", - name: "delegatebw" - }); - }); - }); + data: '01000000000000000100000000000000881300000000000004454f5300000000102700000000000004454f530000000000', + name: 'delegatebw', + }) + }) + }) suite('undelegateResources', () => { test('returns current Action', () => { - const action = testAccount.undelegateResources("0.5000 EOS", "1.0000 EOS"); + const action = testAccount.undelegateResources('0.5000 EOS', '1.0000 EOS') assert.deepEqual(deserialize(action), { - account: "eosio", + account: 'eosio', authorization: [ { - actor: "............1", - permission: "............2" - } + actor: '............1', + permission: '............2', + }, ], - data: "01000000000000000100000000000000102700000000000004454f5300000000881300000000000004454f5300000000", - name: "undelegatebw" - }); - }); - }); + data: '01000000000000000100000000000000102700000000000004454f5300000000881300000000000004454f5300000000', + name: 'undelegatebw', + }) + }) + }) suite('getBalance', function () { this.slow(200) diff --git a/test/tests/kit.ts b/test/tests/kit.ts index face5e3..b872015 100644 --- a/test/tests/kit.ts +++ b/test/tests/kit.ts @@ -1,49 +1,52 @@ import {assert, expect} from 'chai' -import { APIClient } from '@wharfkit/antelope'; +import {APIClient} from '@wharfkit/antelope' -import { Account, AccountKit } from '../../src'; -import { MockProvider } from 'test/utils/mock-provider'; +import {Account, AccountKit} from '../../src' +import {MockProvider} from 'test/utils/mock-provider' const eosApiClient = new APIClient({ provider: new MockProvider('https://eos.greymass.com'), }) -suite('AccountKit', function() { - let accountKit: AccountKit; +suite('AccountKit', function () { + let accountKit: AccountKit - this.beforeAll(function() { - const client = eosApiClient; - accountKit = new AccountKit({ client }); - }); + this.beforeAll(function () { + const client = eosApiClient + accountKit = new AccountKit({client}) + }) - suite('constructor', function() { - test('throws error if client is not provided', function() { + suite('constructor', function () { + test('throws error if client is not provided', function () { try { new AccountKit({} as any) } catch (error) { - assert.equal(error.message, 'A `client` must be passed when initializing the AccountKit.'); + assert.equal( + error.message, + 'A `client` must be passed when initializing the AccountKit.' + ) } - }); + }) - test('sets client if provided', function() { - expect(accountKit.client).to.exist; - }); - }); + test('sets client if provided', function () { + expect(accountKit.client).to.exist + }) + }) - suite('load', function() { - test('throws error if account does not exist', async function() { + suite('load', function () { + test('throws error if account does not exist', async function () { try { - await accountKit.load('nonexistent'); - assert.fail(); + await accountKit.load('nonexistent') + assert.fail() } catch (error) { - assert.equal(error.message, 'Account nonexistent does not exist'); + assert.equal(error.message, 'Account nonexistent does not exist') } - }); + }) - test('returns an Account object when account exists', async function() { - const account = await accountKit.load('teamgreymass'); - expect(account).to.be.instanceOf(Account); + test('returns an Account object when account exists', async function () { + const account = await accountKit.load('teamgreymass') + expect(account).to.be.instanceOf(Account) }) - }); -}); + }) +}) diff --git a/test/tests/permissions.ts b/test/tests/permissions.ts index ecc5a3c..2d52faf 100644 --- a/test/tests/permissions.ts +++ b/test/tests/permissions.ts @@ -1,8 +1,8 @@ import {assert} from 'chai' -import {Authority, Name, NameType, AuthorityType} from '@wharfkit/antelope' +import {Authority, AuthorityType, Name, NameType} from '@wharfkit/antelope' import {ActionData, Permission} from '../../src' -import { deserialize } from '../utils/helpers' +import {deserialize} from '../utils/helpers' const authorityExample = { threshold: 1, @@ -128,4 +128,3 @@ function testPermission() { }), }) } - diff --git a/test/utils/helpers.ts b/test/utils/helpers.ts index cdfc0c0..91a2526 100644 --- a/test/utils/helpers.ts +++ b/test/utils/helpers.ts @@ -1,3 +1,3 @@ export function deserialize(data: DataType) { - return JSON.parse(JSON.stringify(data)) -} \ No newline at end of file + return JSON.parse(JSON.stringify(data)) +} diff --git a/test/utils/mock-data.ts b/test/utils/mock-data.ts index eb0c74f..5b72cc1 100644 --- a/test/utils/mock-data.ts +++ b/test/utils/mock-data.ts @@ -1,5 +1,5 @@ import {API, Asset, Name, TimePoint, UInt32, UInt64} from '@greymass/eosio' -import { deserialize } from './helpers' +import {deserialize} from './helpers' export const mockAccountObject = API.v1.AccountObject.from({ cpu_weight: UInt64.from(236250),