11import { expect , describe , test } from "vitest" ;
22import { Future , Trace } from "substrate/Future" ;
33import { Node } from "substrate/Node" ;
4- import { makeProxyFactory , isProxy , unproxy } from "substrate/ProxiedFuture" ;
4+ import { proxyFactory , isProxy , unproxy } from "substrate/ProxiedFuture" ;
55
66class FooFuture extends Future < any > { }
77class FooNode extends Node { }
@@ -11,15 +11,13 @@ const node = (id: string = "") => new FooNode({}, { id });
1111describe ( "ProxiedFuture" , ( ) => {
1212 describe ( "ProxyFactory" , ( ) => {
1313 test ( "makeProxy" , ( ) => {
14- const proxyFactory = makeProxyFactory ( ) ;
1514 const f = new FooFuture ( new Trace ( [ ] , node ( ) ) ) ;
1615 const p = proxyFactory . makeProxy ( f ) ;
1716 // Proxy is an instance of Future
1817 expect ( p ) . instanceof ( Future ) ;
1918 } ) ;
2019
2120 test ( "isProxy" , ( ) => {
22- const proxyFactory = makeProxyFactory ( ) ;
2321 const f = new FooFuture ( new Trace ( [ ] , node ( ) ) ) ;
2422 const p = proxyFactory . makeProxy ( f ) ;
2523 // We can detect whether the proxied Future is a proxy
@@ -30,7 +28,6 @@ describe("ProxiedFuture", () => {
3028
3129 describe ( "Proxy" , ( ) => {
3230 test ( "unproxy (returns unproxied Future)" , ( ) => {
33- const proxyFactory = makeProxyFactory ( ) ;
3431 const f = new FooFuture ( new Trace ( [ ] , node ( ) ) ) ;
3532 const p = proxyFactory . makeProxy ( f ) ;
3633 const up = unproxy ( p ) ;
@@ -39,16 +36,13 @@ describe("ProxiedFuture", () => {
3936 } ) ;
4037
4138 test ( "arbitrary property access (. notation)" , ( ) => {
42- const proxyFactory = makeProxyFactory ( ) ;
4339 const f = new FooFuture ( new Trace ( [ ] , node ( "123" ) ) ) ;
4440 const p = proxyFactory . makeProxy ( f ) ;
4541
46- // @ts -ignore (properties don't exist)
4742 const f1 = p . a . b . c ;
4843 expect ( f1 ) . instanceof ( Future ) ;
4944 expect ( isProxy ( f1 ) ) . toEqual ( true ) ;
5045
51- // @ts -ignore ("virtual property" doesn't exist)
5246 const up = unproxy ( f1 ) ;
5347 const json = up . toJSON ( ) ;
5448
@@ -64,7 +58,6 @@ describe("ProxiedFuture", () => {
6458 } ) ;
6559
6660 test ( "arbitrary property and index access (brackets)" , ( ) => {
67- const proxyFactory = makeProxyFactory ( ) ;
6861 const f = new FooFuture ( new Trace ( [ ] , node ( "123" ) ) ) ;
6962 const p = proxyFactory . makeProxy ( f ) ;
7063
@@ -86,27 +79,28 @@ describe("ProxiedFuture", () => {
8679 } ) ;
8780 } ) ;
8881
89- // TODO(liam): I'm not sure why this test doesn't work yet, but it does work in example code
90- test . skip ( "using Future values as proxy accessors" , ( ) => {
91- const proxyFactory = makeProxyFactory ( ) ;
82+ test ( "using Future values as proxy accessors" , ( ) => {
9283 const f = new FooFuture ( new Trace ( [ ] , node ( "123" ) ) ) ;
9384 const p = proxyFactory . makeProxy ( f ) ;
9485
9586 const a = new FooFuture ( new Trace ( [ ] , node ( "456" ) ) ) ;
87+ const b = new FooFuture ( new Trace ( [ ] , node ( "789" ) ) ) ;
9688
97- // non index-types are illegal in the type system, so we're casting to any here.
98- const f1 = p [ a as any ] ;
89+ const f1 = p [ a as any ] [ b as any ] ;
9990
10091 expect ( f1 ) . instanceof ( Future ) ;
10192 expect ( isProxy ( f1 ) ) . toEqual ( true ) ;
10293
10394 const up = unproxy ( f1 ) ;
95+
10496 const json = up . toJSON ( ) ;
10597
10698 expect ( json . directive ) . toEqual ( {
10799 op_stack : [
108100 // @ts -ignore
109101 { accessor : "attr" , future_id : a . _id , key : null } ,
102+ // @ts -ignore
103+ { accessor : "attr" , future_id : b . _id , key : null } ,
110104 ] ,
111105 origin_node_id : "123" ,
112106 type : "trace" ,
0 commit comments