|
61 | 61 | urlContractQuery = "/namespaces/default/contracts/query" |
62 | 62 | urlContractInterface = "/namespaces/default/contracts/interfaces" |
63 | 63 | urlContractListeners = "/namespaces/default/contracts/listeners" |
| 64 | + urlContractAPI = "/namespaces/default/apis" |
64 | 65 | urlBlockchainEvents = "/namespaces/default/blockchainevents" |
65 | 66 | urlGetOrganizations = "/network/organizations" |
66 | 67 | urlGetOrgKeys = "/namespaces/ff_system/identities/%s/verifiers" |
@@ -650,15 +651,15 @@ func CreateFFIContractListener(t *testing.T, client *resty.Client, ffiReference |
650 | 651 | }, |
651 | 652 | EventPath: eventPath, |
652 | 653 | } |
653 | | - var sub fftypes.ContractListener |
| 654 | + var listener fftypes.ContractListener |
654 | 655 | path := urlContractListeners |
655 | 656 | resp, err := client.R(). |
656 | 657 | SetBody(&body). |
657 | | - SetResult(&sub). |
| 658 | + SetResult(&listener). |
658 | 659 | Post(path) |
659 | 660 | require.NoError(t, err) |
660 | 661 | require.Equal(t, 200, resp.StatusCode(), "POST %s [%d]: %s", path, resp.StatusCode(), resp.String()) |
661 | | - return &sub |
| 662 | + return &listener |
662 | 663 | } |
663 | 664 |
|
664 | 665 | func GetContractListeners(t *testing.T, client *resty.Client, startTime time.Time) (subs []*fftypes.ContractListener) { |
@@ -728,6 +729,71 @@ func CreateFFI(t *testing.T, client *resty.Client, ffi *fftypes.FFI) (interface{ |
728 | 729 | return res, err |
729 | 730 | } |
730 | 731 |
|
| 732 | +func CreateContractAPI(t *testing.T, client *resty.Client, name string, FFIReference *fftypes.FFIReference, location *fftypes.JSONAny) (interface{}, error) { |
| 733 | + apiReqBody := &fftypes.ContractAPI{ |
| 734 | + Name: name, |
| 735 | + Interface: FFIReference, |
| 736 | + Location: location, |
| 737 | + } |
| 738 | + |
| 739 | + var res interface{} |
| 740 | + path := urlContractAPI |
| 741 | + resp, err := client.R(). |
| 742 | + SetBody(apiReqBody). |
| 743 | + SetResult(&res). |
| 744 | + SetQueryParam("confirm", "true"). |
| 745 | + Post(path) |
| 746 | + require.NoError(t, err) |
| 747 | + require.Equal(t, 200, resp.StatusCode(), "POST %s [%d]: %s", path, resp.StatusCode(), resp.String()) |
| 748 | + return res, err |
| 749 | +} |
| 750 | + |
| 751 | +func InvokeContractAPIMethod(t *testing.T, client *resty.Client, APIName string, methodName string, input *fftypes.JSONAny) (interface{}, error) { |
| 752 | + apiReqBody := map[string]interface{}{ |
| 753 | + "input": input, |
| 754 | + } |
| 755 | + var res interface{} |
| 756 | + path := fmt.Sprintf("%s/%s/invoke/%s", urlContractAPI, APIName, methodName) |
| 757 | + resp, err := client.R(). |
| 758 | + SetBody(apiReqBody). |
| 759 | + SetResult(&res). |
| 760 | + SetQueryParam("confirm", "true"). |
| 761 | + Post(path) |
| 762 | + require.NoError(t, err) |
| 763 | + require.Equal(t, 200, resp.StatusCode(), "POST %s [%d]: %s", path, resp.StatusCode(), resp.String()) |
| 764 | + return res, err |
| 765 | +} |
| 766 | + |
| 767 | +func QueryContractAPIMethod(t *testing.T, client *resty.Client, APIName string, methodName string, input *fftypes.JSONAny) (interface{}, error) { |
| 768 | + apiReqBody := map[string]interface{}{ |
| 769 | + "input": input, |
| 770 | + } |
| 771 | + var res interface{} |
| 772 | + path := fmt.Sprintf("%s/%s/query/%s", urlContractAPI, APIName, methodName) |
| 773 | + resp, err := client.R(). |
| 774 | + SetBody(apiReqBody). |
| 775 | + SetResult(&res). |
| 776 | + Post(path) |
| 777 | + require.NoError(t, err) |
| 778 | + require.Equal(t, 200, resp.StatusCode(), "POST %s [%d]: %s", path, resp.StatusCode(), resp.String()) |
| 779 | + return res, err |
| 780 | +} |
| 781 | + |
| 782 | +func CreateContractAPIListener(t *testing.T, client *resty.Client, APIName, eventName, topic string) (*fftypes.ContractListener, error) { |
| 783 | + apiReqBody := map[string]interface{}{ |
| 784 | + "topic": topic, |
| 785 | + } |
| 786 | + var listener fftypes.ContractListener |
| 787 | + path := fmt.Sprintf("%s/%s/listeners/%s", urlContractAPI, APIName, eventName) |
| 788 | + resp, err := client.R(). |
| 789 | + SetBody(apiReqBody). |
| 790 | + SetResult(&listener). |
| 791 | + Post(path) |
| 792 | + require.NoError(t, err) |
| 793 | + require.Equal(t, 200, resp.StatusCode(), "POST %s [%d]: %s", path, resp.StatusCode(), resp.String()) |
| 794 | + return &listener, err |
| 795 | +} |
| 796 | + |
731 | 797 | func GetEvent(t *testing.T, client *resty.Client, eventID string) (interface{}, error) { |
732 | 798 | var res interface{} |
733 | 799 | path := fmt.Sprintf("%s/%s", urlGetEvents, eventID) |
|
0 commit comments