generated from wharfkit/wallet-plugin-template
-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from apporc/apporc
Support scatter desktop
- Loading branch information
Showing
7 changed files
with
698 additions
and
291 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import {Struct} from '@wharfkit/antelope' | ||
|
||
@Struct.type('scatter_account') | ||
export class ScatterAccount extends Struct { | ||
@Struct.field('authority') authority!: string | ||
@Struct.field('blockchain') blockchain!: string | ||
@Struct.field('chainId') chainId!: string | ||
@Struct.field('isHardware') isHardware!: boolean | ||
@Struct.field('name') name!: string | ||
@Struct.field('publicKey') publicKey!: string | ||
} | ||
@Struct.type('scatter_identity') | ||
export class ScatterIdentity extends Struct { | ||
@Struct.field('accounts') accounts!: ScatterAccount[] | ||
@Struct.field('hash') hash!: string | ||
@Struct.field('name') name!: string | ||
@Struct.field('publicKey') publicKey!: string | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,51 +1,60 @@ | ||
import {assert} from 'chai' | ||
import {PermissionLevel, SessionKit} from '@wharfkit/session' | ||
import { | ||
mockChainDefinition, | ||
mockPermissionLevel, | ||
mockSessionKitArgs, | ||
mockSessionKitOptions, | ||
} from '@wharfkit/mock-data' | ||
|
||
import {WalletPluginTEMPLATE} from '$lib' | ||
import {WalletPluginScatter} from '$lib' | ||
import {mockFetch} from '$test/utils/mock-fetch' | ||
import {MockStorage} from '$test/utils/mock-storage' | ||
import {MockUserInterface} from '$test/utils/mock-ui' | ||
|
||
const mockChainDefinition = { | ||
id: 'aca376f206b8fc25a6ed44dbdc66547c36c6c33e3a119ffbeaef943642f0e906', | ||
url: 'https://eos.greymass.com', | ||
} | ||
|
||
const mockPermissionLevel = PermissionLevel.from('wharfkit1111@test') | ||
|
||
const mockSessionKitOptions = { | ||
appName: 'unittests', | ||
chains: [mockChainDefinition], | ||
fetch: mockFetch, // Required for unit tests | ||
storage: new MockStorage(), | ||
ui: new MockUserInterface(), | ||
walletPlugins: [new WalletPluginScatter()], | ||
} | ||
|
||
suite('wallet plugin', function () { | ||
test('login and sign', async function () { | ||
const kit = new SessionKit( | ||
{ | ||
...mockSessionKitArgs, | ||
walletPlugins: [new WalletPluginTEMPLATE()], | ||
}, | ||
mockSessionKitOptions | ||
) | ||
const {session} = await kit.login({ | ||
chain: mockChainDefinition.id, | ||
permissionLevel: mockPermissionLevel, | ||
}) | ||
assert.isTrue(session.chain.equals(mockChainDefinition)) | ||
assert.isTrue(session.actor.equals(PermissionLevel.from(mockPermissionLevel).actor)) | ||
assert.isTrue( | ||
session.permission.equals(PermissionLevel.from(mockPermissionLevel).permission) | ||
) | ||
const result = await session.transact( | ||
{ | ||
action: { | ||
authorization: [PermissionLevel.from(mockPermissionLevel)], | ||
account: 'eosio.token', | ||
name: 'transfer', | ||
data: { | ||
from: PermissionLevel.from(mockPermissionLevel).actor, | ||
to: 'wharfkittest', | ||
quantity: '0.0001 EOS', | ||
memo: 'wharfkit/session wallet plugin template', | ||
}, | ||
}, | ||
}, | ||
{ | ||
broadcast: false, | ||
} | ||
) | ||
assert.isTrue(result.signer.equals(mockPermissionLevel)) | ||
assert.equal(result.signatures.length, 1) | ||
}) | ||
this.timeout(120 * 1000) | ||
this.slow(5 * 1000) | ||
|
||
// test('login and sign', async function () { | ||
|
||
// const kit = new SessionKit(mockSessionKitOptions) | ||
// const { session } = await kit.login({ | ||
// chain: mockChainDefinition.id, | ||
// permissionLevel: mockPermissionLevel, | ||
// }) | ||
// assert.isTrue(session.chain.equals(mockChainDefinition)) | ||
// assert.isTrue(session.actor.equals(mockPermissionLevel.actor)) | ||
// assert.isTrue(session.permission.equals(mockPermissionLevel.permission)) | ||
// const result = await session.transact( | ||
// { | ||
// action: { | ||
// authorization: [mockPermissionLevel], | ||
// account: 'eosio.token', | ||
// name: 'transfer', | ||
// data: { | ||
// from: mockPermissionLevel.actor, | ||
// to: 'wharfkittest', | ||
// quantity: '0.0001 EOS', | ||
// memo: 'wharfkit/session wallet plugin template', | ||
// }, | ||
// }, | ||
// }, | ||
// { | ||
// broadcast: false, | ||
// } | ||
// ) | ||
// assert.isTrue(result.signer.equals(mockPermissionLevel)) | ||
// assert.equal(result.signatures.length, 1) | ||
// }) | ||
}) |
Oops, something went wrong.