1- import test from 'node:test' ;
2- import assert from 'node:assert/strict' ;
3- import { onRpcRequest } from '../dist/ecency-snap.es.js' ;
1+ import test from "node:test" ;
2+ import assert from "node:assert/strict" ;
3+ import { onRpcRequest } from "../dist/bundle.js" ;
4+ import { getLastSignExternalTxParams } from "./mock-wallets.js" ;
45import { getLastSignExternalTxParams } from './mock-wallets.js' ;
56
67const state = { } ;
78
89// simple snap state stub
910globalThis . snap = {
1011 request : async ( { method, params } ) => {
11- if ( method !== ' snap_manageState' ) throw new Error ( ' unsupported' ) ;
12- if ( params . operation === ' get' ) return state ;
13- if ( params . operation === ' update' ) {
12+ if ( method !== " snap_manageState" ) throw new Error ( " unsupported" ) ;
13+ if ( params . operation === " get" ) return state ;
14+ if ( params . operation === " update" ) {
1415 Object . assign ( state , params . newState ) ;
1516 return null ;
1617 }
17- throw new Error ( ' bad operation' ) ;
18+ throw new Error ( " bad operation" ) ;
1819 } ,
1920} ;
2021
21- const mnemonic = ' test test test test test test test test test test test junk' ;
22+ const mnemonic = " test test test test test test test test test test test junk" ;
2223
23- test ( 'initialize and unlock' , async ( ) => {
24- const init = await onRpcRequest ( { origin : 'test' , request : { method : 'initialize' , params : { mnemonic } } } ) ;
24+ test ( "initialize and unlock" , async ( ) => {
25+ const init = await onRpcRequest ( {
26+ origin : "test" ,
27+ request : { method : "initialize" , params : { mnemonic } } ,
28+ } ) ;
2529 assert . equal ( init , true ) ;
2630
27- const unlock = await onRpcRequest ( { origin : 'test' , request : { method : 'unlock' , params : { mnemonic } } } ) ;
31+ const unlock = await onRpcRequest ( {
32+ origin : "test" ,
33+ request : { method : "unlock" , params : { mnemonic } } ,
34+ } ) ;
2835 assert . equal ( unlock , true ) ;
2936} ) ;
3037
31- test ( 'get hive address' , async ( ) => {
32- await onRpcRequest ( { origin : 'test' , request : { method : 'initialize' , params : { mnemonic } } } ) ;
33- const res = await onRpcRequest ( { origin : 'test' , request : { method : 'getAddress' , params : { chain : 'HIVE' } } } ) ;
38+ test ( "get hive address" , async ( ) => {
39+ await onRpcRequest ( {
40+ origin : "test" ,
41+ request : { method : "initialize" , params : { mnemonic } } ,
42+ } ) ;
43+ const res = await onRpcRequest ( {
44+ origin : "test" ,
45+ request : { method : "getAddress" , params : { chain : "HIVE" } } ,
46+ } ) ;
3447 assert . ok ( res . address ) ;
3548} ) ;
3649
37- test ( 'sign hive tx' , async ( ) => {
38- await onRpcRequest ( { origin : 'test' , request : { method : 'initialize' , params : { mnemonic } } } ) ;
39- const tx = { ref_block_num : 0 , ref_block_prefix : 0 , expiration : '2020-01-01T00:00:00' , operations : [ ] , extensions : [ ] } ;
40- const signed = await onRpcRequest ( { origin : 'test' , request : { method : 'signHiveTx' , params : { tx } } } ) ;
50+ test ( "sign hive tx" , async ( ) => {
51+ await onRpcRequest ( {
52+ origin : "test" ,
53+ request : { method : "initialize" , params : { mnemonic } } ,
54+ } ) ;
55+ const tx = {
56+ ref_block_num : 0 ,
57+ ref_block_prefix : 0 ,
58+ expiration : "2020-01-01T00:00:00" ,
59+ operations : [ ] ,
60+ extensions : [ ] ,
61+ } ;
62+ const signed = await onRpcRequest ( {
63+ origin : "test" ,
64+ request : { method : "signHiveTx" , params : { tx } } ,
65+ } ) ;
4166 assert . ok ( Array . isArray ( signed . signatures ) ) ;
4267} ) ;
4368
@@ -51,9 +76,33 @@ test('sign external tx', async () => {
5176 assert . equal ( getLastSignExternalTxParams ( ) . privateKey , 'priv' ) ;
5277} ) ;
5378
54- test ( 'balance query placeholder' , async ( ) => {
55- await onRpcRequest ( { origin : 'test' , request : { method : 'initialize' , params : { mnemonic } } } ) ;
56- const bal = await onRpcRequest ( { origin : 'test' , request : { method : 'getBalance' , params : { currency : 'BTC' , address : 'xyz' } } } ) ;
79+ test ( "balance query placeholder" , async ( ) => {
80+ await onRpcRequest ( {
81+ origin : "test" ,
82+ request : { method : "initialize" , params : { mnemonic } } ,
83+ } ) ;
84+ const bal = await onRpcRequest ( {
85+ origin : "test" ,
86+ request : {
87+ method : "getBalance" ,
88+ params : { currency : "BTC" , address : "xyz" } ,
89+ } ,
90+ } ) ;
5791 assert . equal ( bal , 0 ) ;
5892} ) ;
93+ test ( "sign external tx" , async ( ) => {
94+ await onRpcRequest ( {
95+ origin : "test" ,
96+ request : { method : "initialize" , params : { mnemonic } } ,
97+ } ) ;
98+ const res = await onRpcRequest ( {
99+ origin : "test" ,
100+ request : {
101+ method : "signExternalTx" ,
102+ params : { currency : "BTC" , params : { foo : "bar" } } ,
103+ } ,
104+ } ) ;
105+ assert . equal ( res , "signed" ) ;
106+ assert . equal ( getLastSignExternalTxParams ( ) . privateKey , "priv" ) ;
107+ } ) ;
59108
0 commit comments