From d70b2ddeb969251af64b8915887d9b9bc7d68983 Mon Sep 17 00:00:00 2001 From: dafuga Date: Wed, 6 Sep 2023 19:00:30 -0700 Subject: [PATCH] chore: added linkauth and unlinkauth Account methods --- src/account.ts | 21 ++++++++++++++++----- test/tests/account.ts | 26 ++++++++++++++++++++++++++ 2 files changed, 42 insertions(+), 5 deletions(-) diff --git a/src/account.ts b/src/account.ts index 46b4834..204baf3 100644 --- a/src/account.ts +++ b/src/account.ts @@ -42,7 +42,7 @@ export interface UndelegateOptions { export class Account { readonly data: API.v1.AccountObject - readonly systemContract: Contract + readonly systemContract: SystemContract.Contract readonly client: APIClient constructor(args: AccountArgs) { @@ -141,12 +141,23 @@ export class Account { }) } - linkauth() { - // TODO: Implement `linkauth` action calls + linkauth(contract: NameType, action: NameType, requirement: NameType): Action { + return this.systemContract.action('linkauth', { + account: this.accountName, + code: contract, + type: action, + requirement: requirement, + authorized_by: '', + }) } - unlinkauth() { - // TODO: Implement `unlinkauth` action calls + unlinkauth(contract: NameType, action: NameType): Action { + return this.systemContract.action('unlinkauth', { + account: this.accountName, + code: contract, + type: action, + authorized_by: '', + }); } buyRam(amount: AssetType, options?: BuyramOptions): Action { diff --git a/test/tests/account.ts b/test/tests/account.ts index 0cb9cd5..51a656e 100644 --- a/test/tests/account.ts +++ b/test/tests/account.ts @@ -217,6 +217,31 @@ suite('Account', function () { }) }) + test('linkauth', () => { + const action = testAccount.linkauth('eosio.token', 'transfer', 'active'); + assert.isTrue(action.account.equals('eosio')); + assert.isTrue(action.name.equals('linkauth')); + assert.isTrue(action.authorization[0].equals(PlaceholderAuth)); + + const decoded = Serializer.decode({data: action.data, type: SystemContract.Types.Linkauth}); + assert.isTrue(decoded.account.equals('wharfkit1133')); + assert.isTrue(decoded.code.equals('eosio.token')); + assert.isTrue(decoded.type.equals('transfer')); + assert.isTrue(decoded.requirement.equals('active')); + }); + + test('unlinkauth', () => { + const action = testAccount.unlinkauth('eosio.token', 'transfer'); + assert.isTrue(action.account.equals('eosio')); + assert.isTrue(action.name.equals('unlinkauth')); + assert.isTrue(action.authorization[0].equals(PlaceholderAuth)); + + const decoded = Serializer.decode({data: action.data, type: SystemContract.Types.Unlinkauth}); + assert.isTrue(decoded.account.equals('wharfkit1133')); + assert.isTrue(decoded.code.equals('eosio.token')); + assert.isTrue(decoded.type.equals('transfer')); + }); + suite('buyRam', () => { test('only amount', () => { const action = testAccount.buyRam('1.0000 EOS') @@ -293,6 +318,7 @@ suite('Account', function () { assert.isTrue(decoded.account.equals('wharfkit1133')) assert.isTrue(decoded.bytes.equals(1024)) }) + suite('delegate', () => { test('no data', () => {