@@ -2582,6 +2582,101 @@ func TestQueryContractOK(t *testing.T) {
2582
2582
assert .Equal (t , `{"output":"3"}` , string (j ))
2583
2583
}
2584
2584
2585
+ func TestQueryContractMultipleUnnamedOutputOK (t * testing.T ) {
2586
+ e , cancel := newTestEthereum ()
2587
+ defer cancel ()
2588
+ httpmock .ActivateNonDefault (e .client .GetClient ())
2589
+ defer httpmock .DeactivateAndReset ()
2590
+ location := & Location {
2591
+ Address : "0x12345" ,
2592
+ }
2593
+ method := testFFIMethod ()
2594
+ errors := testFFIErrors ()
2595
+ params := map [string ]interface {}{}
2596
+ options := map [string ]interface {}{
2597
+ "customOption" : "customValue" ,
2598
+ }
2599
+
2600
+ outputStruct := struct {
2601
+ Test string `json:"test"`
2602
+ Value int `json:"value"`
2603
+ }{
2604
+ Test : "myvalue" ,
2605
+ Value : 3 ,
2606
+ }
2607
+
2608
+ output := map [string ]interface {}{
2609
+ "output" : "foo" ,
2610
+ "output1" : outputStruct ,
2611
+ "anything" : 3 ,
2612
+ }
2613
+
2614
+ locationBytes , err := json .Marshal (location )
2615
+ assert .NoError (t , err )
2616
+ httpmock .RegisterResponder ("POST" , `http://localhost:12345/` ,
2617
+ func (req * http.Request ) (* http.Response , error ) {
2618
+ var body map [string ]interface {}
2619
+ json .NewDecoder (req .Body ).Decode (& body )
2620
+ headers := body ["headers" ].(map [string ]interface {})
2621
+ assert .Equal (t , "Query" , headers ["type" ])
2622
+ assert .Equal (t , "customValue" , body ["customOption" ].(string ))
2623
+ assert .Equal (t , "0x12345" , body ["to" ].(string ))
2624
+ return httpmock .NewJsonResponderOrPanic (200 , output )(req )
2625
+ })
2626
+ result , err := e .QueryContract (context .Background (), fftypes .JSONAnyPtrBytes (locationBytes ), method , params , errors , options )
2627
+ assert .NoError (t , err )
2628
+ j , err := json .Marshal (result )
2629
+ assert .NoError (t , err )
2630
+ assert .Equal (t , `{"anything":3,"output":"foo","output1":{"test":"myvalue","value":3}}` , string (j ))
2631
+ }
2632
+
2633
+ func TestQueryContractNamedOutputOK (t * testing.T ) {
2634
+ e , cancel := newTestEthereum ()
2635
+ defer cancel ()
2636
+ httpmock .ActivateNonDefault (e .client .GetClient ())
2637
+ defer httpmock .DeactivateAndReset ()
2638
+ location := & Location {
2639
+ Address : "0x12345" ,
2640
+ }
2641
+ method := testFFIMethod ()
2642
+ errors := testFFIErrors ()
2643
+ params := map [string ]interface {}{}
2644
+ options := map [string ]interface {}{
2645
+ "customOption" : "customValue" ,
2646
+ }
2647
+
2648
+ outputStruct := struct {
2649
+ Test string `json:"test"`
2650
+ Value int `json:"value"`
2651
+ }{
2652
+ Test : "myvalue" ,
2653
+ Value : 3 ,
2654
+ }
2655
+
2656
+ output := map [string ]interface {}{
2657
+ "mynamedparam" : "foo" ,
2658
+ "mynamedstruct" : outputStruct ,
2659
+ }
2660
+
2661
+ locationBytes , err := json .Marshal (location )
2662
+ assert .NoError (t , err )
2663
+ httpmock .RegisterResponder ("POST" , `http://localhost:12345/` ,
2664
+ func (req * http.Request ) (* http.Response , error ) {
2665
+ var body map [string ]interface {}
2666
+ json .NewDecoder (req .Body ).Decode (& body )
2667
+ headers := body ["headers" ].(map [string ]interface {})
2668
+ assert .Equal (t , "Query" , headers ["type" ])
2669
+ assert .Equal (t , "customValue" , body ["customOption" ].(string ))
2670
+ assert .Equal (t , "0x12345" , body ["to" ].(string ))
2671
+ return httpmock .NewJsonResponderOrPanic (200 , output )(req )
2672
+ })
2673
+ result , err := e .QueryContract (context .Background (), fftypes .JSONAnyPtrBytes (locationBytes ), method , params , errors , options )
2674
+ assert .NoError (t , err )
2675
+ j , err := json .Marshal (result )
2676
+ assert .NoError (t , err )
2677
+ assert .Equal (t , `{"mynamedparam":"foo","mynamedstruct":{"test":"myvalue","value":3}}` , string (j ))
2678
+ }
2679
+
2585
2680
func TestQueryContractInvalidOption (t * testing.T ) {
2586
2681
e , cancel := newTestEthereum ()
2587
2682
defer cancel ()
0 commit comments