Skip to content

Commit

Permalink
chore: added linkauth and unlinkauth Account methods
Browse files Browse the repository at this point in the history
closes issue #12
  • Loading branch information
dafuga committed Sep 7, 2023
1 parent 1fa971f commit 36ed958
Show file tree
Hide file tree
Showing 2 changed files with 44 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, requiredPermission: NameType): Action {
return this.systemContract.action('linkauth', {
account: this.accountName,
code: contract,
type: action,
requirement: requiredPermission,
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
28 changes: 28 additions & 0 deletions test/tests/account.ts
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,34 @@ 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

0 comments on commit 36ed958

Please sign in to comment.