Skip to content

Commit

Permalink
fix(client): change interface (#37)
Browse files Browse the repository at this point in the history
  • Loading branch information
nmvalera authored May 30, 2023
1 parent df48d20 commit f7ded26
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 20 deletions.
7 changes: 4 additions & 3 deletions pkg/defender/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,10 @@ type CreateProposalReqMsg struct {
Via string `json:"via"`
ViaType string `json:"viaType"`

Contract ContractMsg `json:"contract"`
FunctionInterface FunctionInterface `json:"targetFunction"`
FunctionInputs []interface{} `json:"functionInputs"`
Contract ContractMsg `json:"contract"`
TargetFunction *FunctionInterface `json:"targetFunction,omitempty"`
FunctionInterface *FunctionInterface `json:"functionInterface,omitempty"`
FunctionInputs []interface{} `json:"functionInputs"`

Metadata *ProposalMetadata `json:"metadata,omitempty"`
}
Expand Down
47 changes: 43 additions & 4 deletions pkg/defender/client/http/proposals_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package defenderclienthttp

import (
"context"
"os"
"testing"

defenderclient "github.com/liquid-collective/terraform-provider-openzeppelin-defender/pkg/defender/client"
Expand All @@ -10,8 +11,8 @@ import (

func newClient() (*Client, error) { //nolint
client, err := New((&Config{
APIKey: "<placeholder>",
APISecret: "<placeholder>",
APIKey: os.Getenv("DEFENDER_API_KEY"),
APISecret: os.Getenv("DEFENDER_API_SECRET"),
}).SetDefault())

if err != nil {
Expand All @@ -26,18 +27,56 @@ func newClient() (*Client, error) { //nolint
return client, nil
}

func testCreateSendUSDCProposal(t testing.TB) { //nolint
func testCreateAddOperatorProposal(t *testing.T) { //nolint
client, err := newClient()
require.NoError(t, err)

reqMsg := &defenderclient.CreateProposalReqMsg{
Title: "Test (to be archived)",
Via: "0xE3208Aa9d1186c1D1C8A5b76E794b2B68E6cb3a5",
ViaType: "Gnosis Safe",
Contract: defenderclient.ContractMsg{
Network: "mainnet",
Address: "0xAF5ae0768291C4ADC57Cb7e1482F336b4Faa4291",
},
TargetFunction: &defenderclient.FunctionInterface{
Name: "",
Inputs: []defenderclient.Inputs{},
},
FunctionInterface: &defenderclient.FunctionInterface{
Name: "addOperator",
Inputs: []defenderclient.Inputs{
{
Name: "_name",
Type: "string",
},
{
Name: "_operator",
Type: "address",
},
},
},
FunctionInputs: []interface{}{"test", "0x0000000000000000000000000000000000000000"},
Type: "custom",
}

_, err = client.CreateProposal(context.TODO(), reqMsg)
require.NoError(t, err)
}

func testCreateSendUSDCProposal(t *testing.T) { //nolint
client, err := newClient()
require.NoError(t, err)

reqMsg := &defenderclient.CreateProposalReqMsg{
Title: "Test (to be archived)",
Via: "0xE3208Aa9d1186c1D1C8A5b76E794b2B68E6cb3a5",
ViaType: "Gnosis Safe",
Contract: defenderclient.ContractMsg{
Network: "mainnet",
Address: "0xE3208Aa9d1186c1D1C8A5b76E794b2B68E6cb3a5",
},
FunctionInterface: defenderclient.FunctionInterface{
TargetFunction: &defenderclient.FunctionInterface{
Name: "",
Inputs: []defenderclient.Inputs{},
},
Expand Down
31 changes: 19 additions & 12 deletions src/provider/resource_defender_proposal.go
Original file line number Diff line number Diff line change
Expand Up @@ -198,23 +198,30 @@ func proposalCreate(ctx context.Context, d *schema.ResourceData, meta interface{
Network: d.Get("contract_network").(string),
Address: d.Get("contract_address").(string),
},
FunctionInterface: defenderclient.FunctionInterface{
Name: d.Get("function_interface_name").(string),
TargetFunction: &defenderclient.FunctionInterface{
Name: "",
Inputs: []defenderclient.Inputs{},
},
FunctionInputs: d.Get("function_inputs").([]interface{}),
}

inputs := d.Get("function_interface_inputs").([]interface{})
for _, input := range inputs {
i := input.(map[string]interface{})
createProposalReq.FunctionInterface.Inputs = append(
createProposalReq.FunctionInterface.Inputs,
defenderclient.Inputs{
Name: i["name"].(string),
Type: i["type"].(string),
},
)
if functionInterfaceName := d.Get("function_interface_name").(string); functionInterfaceName != "" {
createProposalReq.FunctionInterface = &defenderclient.FunctionInterface{
Name: d.Get("function_interface_name").(string),
Inputs: []defenderclient.Inputs{},
}

inputs := d.Get("function_interface_inputs").([]interface{})
for _, input := range inputs {
i := input.(map[string]interface{})
createProposalReq.FunctionInterface.Inputs = append(
createProposalReq.FunctionInterface.Inputs,
defenderclient.Inputs{
Name: i["name"].(string),
Type: i["type"].(string),
},
)
}
}

functionInputsJSON := d.Get("function_inputs_json").(string)
Expand Down
6 changes: 5 additions & 1 deletion src/provider/resource_defender_proposal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ func TestAccResourceProposal(t *testing.T) {
Network: "goerli",
Address: "0x999999cf1046e68e36E1aA2E0E07105eDDD1f08E",
},
FunctionInterface: defenderclient.FunctionInterface{
FunctionInterface: &defenderclient.FunctionInterface{
Name: "testMethod",
Inputs: []defenderclient.Inputs{
{
Expand All @@ -78,6 +78,10 @@ func TestAccResourceProposal(t *testing.T) {
},
},
},
TargetFunction: &defenderclient.FunctionInterface{
Name: "",
Inputs: []defenderclient.Inputs{},
},
FunctionInputs: []interface{}{"1234", "5678"},
Metadata: &defenderclient.ProposalMetadata{
SendTo: "0x5B453a19845e7492ee3A0df4Ef085D4C75e5752b",
Expand Down

0 comments on commit f7ded26

Please sign in to comment.