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', () => {