File tree Expand file tree Collapse file tree 5 files changed +63
-24
lines changed
examples/packages/preinstalled
snaps-simulation/src/store Expand file tree Collapse file tree 5 files changed +63
-24
lines changed Original file line number Diff line number Diff line change 77 "url" : " https://github.com/MetaMask/snaps.git"
88 },
99 "source" : {
10- "shasum" : " iQIQNMXYMDnEaXBghIesd9jKKklaaW/szrGut57SCDc =" ,
10+ "shasum" : " 3ngRXZHVyqZB3sk6u9Hpj2V4SUjrhxb6D/aqesFSmeY =" ,
1111 "location" : {
1212 "npm" : {
1313 "filePath" : " dist/bundle.js" ,
Original file line number Diff line number Diff line change @@ -125,16 +125,27 @@ describe('onRpcRequest', () => {
125125 } ) ;
126126 } ) ;
127127
128- describe ( 'trace ' , ( ) => {
128+ describe ( 'startTrace + endTrace ' , ( ) => {
129129 it ( 'starts and ends a trace' , async ( ) => {
130130 const { request } = await installSnap ( ) ;
131131
132132 const response = await request ( {
133- method : 'trace ' ,
133+ method : 'startTrace ' ,
134134 } ) ;
135135
136- expect ( response ) . toRespondWith ( null ) ;
137- expect ( response ) . toTrace ( {
136+ expect ( response ) . toRespondWith ( {
137+ /* eslint-disable @typescript-eslint/naming-convention */
138+ _traceId : expect . any ( String ) ,
139+ _spanId : expect . any ( String ) ,
140+ /* eslint-enable @typescript-eslint/naming-convention */
141+ } ) ;
142+
143+ const endResponse = await request ( {
144+ method : 'endTrace' ,
145+ } ) ;
146+
147+ expect ( endResponse ) . toRespondWith ( null ) ;
148+ expect ( endResponse ) . toTrace ( {
138149 name : 'Test Snap Trace' ,
139150 } ) ;
140151 } ) ;
Original file line number Diff line number Diff line change @@ -97,22 +97,6 @@ export const onRpcRequest: OnRpcRequestHandler = async ({ request }) => {
9797 } ) ;
9898 }
9999
100- case 'trace' : {
101- await snap . request ( {
102- method : 'snap_startTrace' ,
103- params : {
104- name : 'Test Snap Trace' ,
105- } ,
106- } ) ;
107-
108- return await snap . request ( {
109- method : 'snap_endTrace' ,
110- params : {
111- name : 'Test Snap Trace' ,
112- } ,
113- } ) ;
114- }
115-
116100 default :
117101 throw new MethodNotFoundError ( { method : request . method } ) ;
118102 }
Original file line number Diff line number Diff line change 1- import type { TrackedError , TrackedEvent } from './trackables' ;
1+ import type { TrackablesState , TrackedError , TrackedEvent } from './trackables' ;
22import { trackablesSlice , trackError } from './trackables' ;
33
44describe ( 'trackablesSlice' , ( ) => {
@@ -107,6 +107,51 @@ describe('trackablesSlice', () => {
107107 expect ( state . traces [ 0 ] ) . toStrictEqual ( trace ) ;
108108 } ) ;
109109
110+ it ( 'works in last in first out order' , ( ) => {
111+ const initialState : TrackablesState = {
112+ events : [ ] ,
113+ errors : [ ] ,
114+ traces : [ ] ,
115+ pendingTraces : [
116+ {
117+ id : '123' ,
118+ name : 'Pending Trace' ,
119+ tags : {
120+ 'test-tag' : 'test-value' ,
121+ } ,
122+ } ,
123+ {
124+ id : '123' ,
125+ name : 'Pending Trace' ,
126+ tags : {
127+ 'other-tag' : 'other-value' ,
128+ } ,
129+ } ,
130+ ] ,
131+ } ;
132+
133+ const trace = {
134+ id : '123' ,
135+ name : 'Pending Trace' ,
136+ } ;
137+
138+ const state = trackablesSlice . reducer (
139+ initialState ,
140+ trackablesSlice . actions . endTrace ( trace ) ,
141+ ) ;
142+
143+ expect ( state . pendingTraces ) . toHaveLength ( 1 ) ;
144+ expect ( state . pendingTraces [ 0 ] . id ) . toBe ( '123' ) ;
145+ expect ( state . traces ) . toHaveLength ( 1 ) ;
146+ expect ( state . traces [ 0 ] ) . toStrictEqual ( {
147+ id : '123' ,
148+ name : 'Pending Trace' ,
149+ tags : {
150+ 'other-tag' : 'other-value' ,
151+ } ,
152+ } ) ;
153+ } ) ;
154+
110155 it ( 'does not modify state if trace is not found in pending traces' , ( ) => {
111156 const initialState = {
112157 events : [ ] ,
Original file line number Diff line number Diff line change @@ -65,7 +65,7 @@ export const trackablesSlice = createSlice({
6565 } ,
6666 endTrace : ( state , action : PayloadAction < EndTraceParams > ) => {
6767 const endTrace = castDraft ( action . payload ) ;
68- const index = state . pendingTraces . findIndex (
68+ const index = state . pendingTraces . findLastIndex (
6969 ( pendingTrace ) =>
7070 pendingTrace . id === endTrace . id &&
7171 pendingTrace . name === endTrace . name ,
@@ -81,7 +81,6 @@ export const trackablesSlice = createSlice({
8181 state . events = [ ] ;
8282 state . errors = [ ] ;
8383 state . traces = [ ] ;
84- state . pendingTraces = [ ] ;
8584 } ,
8685 } ,
8786} ) ;
You can’t perform that action at this time.
0 commit comments