Skip to content

Commit

Permalink
chore: added linkauth and unlinkauth Account methods
Browse files Browse the repository at this point in the history
  • Loading branch information
dafuga committed Sep 7, 2023
1 parent 1fa971f commit d70b2dd
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 5 deletions.
21 changes: 16 additions & 5 deletions src/account.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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 {
Expand Down
26 changes: 26 additions & 0 deletions test/tests/account.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down Expand Up @@ -293,6 +318,7 @@ suite('Account', function () {
assert.isTrue(decoded.account.equals('wharfkit1133'))
assert.isTrue(decoded.bytes.equals(1024))
})


suite('delegate', () => {
test('no data', () => {
Expand Down

0 comments on commit d70b2dd

Please sign in to comment.