Skip to content

Commit

Permalink
add test
Browse files Browse the repository at this point in the history
  • Loading branch information
vmidyllic committed Jan 28, 2025
1 parent 54a6811 commit 9a115b1
Showing 1 changed file with 66 additions and 0 deletions.
66 changes: 66 additions & 0 deletions protocol/contract_invoke_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
package protocol_test

import (
"encoding/json"
"testing"

uuid "github.com/google/uuid"
"github.com/iden3/go-rapidsnark/types"
"github.com/iden3/iden3comm/v2/packers"
"github.com/iden3/iden3comm/v2/protocol"
"github.com/stretchr/testify/require"
)

func TestContractInvokeResponseMessageCreation(t *testing.T) {

var err error
id, err := uuid.Parse("f0885dd0-e60e-11ee-b3e8-de17148ce1ce")
require.NoError(t, err)

thID, err := uuid.Parse("f08860d2-e60e-11ee-b3e8-de17148ce1ce")
require.NoError(t, err)

didStr := "did:polygonid:polygon:mumbai:2qK2Rwf2zqzzhqVLqTWXetGUbs1Sc79woomP5cDLBE"
require.NoError(t, err)

proposalRequest := protocol.ContractInvokeResponseMessage{
ID: id.String(),
Typ: packers.MediaTypePlainMessage,
Type: protocol.ContractInvokeResponseMessageType,
ThreadID: thID.String(),
Body: protocol.ContractInvokeResponseMessageBody{
TransactionData: protocol.TransactionData{
ContractAddress: "0x1234",
MethodID: "0x132456",
ChainID: 1,
Network: "polygon-amoy",
},
Scope: []protocol.OnchainZeroKnowledgeProofResponse{
{
ZeroKnowledgeProofResponse: protocol.ZeroKnowledgeProofResponse{
ID: 1,
CircuitID: "234234",
ZKProof: types.ZKProof{
Proof: &types.ProofData{
A: []string{"1", "2"},
B: [][]string{{"1", "2"}, {"3,4"}},
C: []string{"4", "2"},
Protocol: "groth16",
},
PubSignals: []string{"1", "23"},
},
},
TxHash: "0x2345",
},
},
},
From: didStr,
To: "did:polygonid:polygon:mumbai:2qJ689kpoJxcSzB5sAFJtPsSBSrHF5dq722BHMqURL",
}

marshalledReq, err := json.Marshal(proposalRequest)
require.NoError(t, err)
t.Log(string(marshalledReq))
require.JSONEq(t, `{"id":"f0885dd0-e60e-11ee-b3e8-de17148ce1ce","typ":"application/iden3comm-plain-json","type":"https://iden3-communication.io/proofs/1.0/contract-invoke-response","thid":"f08860d2-e60e-11ee-b3e8-de17148ce1ce","body":{"transaction_data":{"contract_address":"0x1234","method_id":"0x132456","chain_id":1,"network":"polygon-amoy"},"scope":[{"id":1,"circuitId":"234234","proof":{"pi_a":["1","2"],"pi_b":[["1","2"],["3,4"]],"pi_c":["4","2"],"protocol":"groth16"},"pub_signals":["1","23"],"txHash":"0x2345"}]},"from":"did:polygonid:polygon:mumbai:2qK2Rwf2zqzzhqVLqTWXetGUbs1Sc79woomP5cDLBE","to":"did:polygonid:polygon:mumbai:2qJ689kpoJxcSzB5sAFJtPsSBSrHF5dq722BHMqURL"}`, string(marshalledReq))

}

0 comments on commit 9a115b1

Please sign in to comment.