From a45007639eca21af1b22cee90d00f65b3c1ad846 Mon Sep 17 00:00:00 2001 From: Dmytro Sukhyi Date: Tue, 4 Jul 2023 18:55:09 +0100 Subject: [PATCH 1/2] update go-merkletree-sql to v2.0.6 --- go.mod | 2 +- go.sum | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/go.mod b/go.mod index 45db5b8..bba61ce 100644 --- a/go.mod +++ b/go.mod @@ -8,7 +8,7 @@ require ( github.com/iden3/go-circuits v1.0.2 github.com/iden3/go-iden3-core v1.0.2 github.com/iden3/go-iden3-crypto v0.0.15 - github.com/iden3/go-merkletree-sql/v2 v2.0.4 + github.com/iden3/go-merkletree-sql/v2 v2.0.6 github.com/iden3/go-schema-processor v1.3.1 github.com/iden3/merkletree-proof v0.0.2 github.com/ipfs/go-ipfs-api v0.6.0 diff --git a/go.sum b/go.sum index 21392ae..4fffb2d 100644 --- a/go.sum +++ b/go.sum @@ -87,6 +87,8 @@ github.com/iden3/go-iden3-crypto v0.0.15 h1:4MJYlrot1l31Fzlo2sF56u7EVFeHHJkxGXXZ github.com/iden3/go-iden3-crypto v0.0.15/go.mod h1:dLpM4vEPJ3nDHzhWFXDjzkn1qHoBeOT/3UEhXsEsP3E= github.com/iden3/go-merkletree-sql/v2 v2.0.4 h1:Dp089P3YNX1BE8+T1tKQHWTtnk84Y/Kr7ZAGTqwscoY= github.com/iden3/go-merkletree-sql/v2 v2.0.4/go.mod h1:kRhHKYpui5DUsry5RpveP6IC4XMe6iApdV9VChRYuEk= +github.com/iden3/go-merkletree-sql/v2 v2.0.6 h1:vsVDImnvnHf7Ggr45ptFOXJyWNA/8IwVQO1jzRLUlY8= +github.com/iden3/go-merkletree-sql/v2 v2.0.6/go.mod h1:kRhHKYpui5DUsry5RpveP6IC4XMe6iApdV9VChRYuEk= github.com/iden3/go-schema-processor v1.3.1 h1:LJfFInfYGMOp0bTKKC17R8q4XI+VtqhFLPTEqnOIvlM= github.com/iden3/go-schema-processor v1.3.1/go.mod h1:NwJ1nuGdRlCFaN1/V6mS0AOAdvpLcGf4KKq0mluLG7U= github.com/iden3/merkletree-proof v0.0.2 h1:a6At2Mm/fEnC8MjsgAmTSrgVsTsKuWGNwdsDU0otJC4= From 0d0a2cc4018dd8f568d8648e11edc6bfbd516c33 Mon Sep 17 00:00:00 2001 From: Oleg Lomaka Date: Wed, 5 Jul 2023 12:05:47 -0400 Subject: [PATCH 2/2] Fix tests --- .../proof_from_smart_contract_out.json | 2 +- go.mod | 2 +- go.sum | 4 -- proof_test.go | 44 +++++++++++++++++++ 4 files changed, 46 insertions(+), 6 deletions(-) diff --git a/examples/testdata/proof_from_smart_contract_out.json b/examples/testdata/proof_from_smart_contract_out.json index 40d5a36..66ac017 100644 --- a/examples/testdata/proof_from_smart_contract_out.json +++ b/examples/testdata/proof_from_smart_contract_out.json @@ -1 +1 @@ -{"root":"17039823904837071705763545555283546217751326723169195059364451777353741017328","proof":{"existence":false,"siblings":["14989532119404983961115670288381063073891118401716735992353404523801340288158","15817549995119513546413395894800310537308858548528902759332598606866792105384","20955911300871905860419417343337237575819647673394656670247178513070221579793","7345857457589225232320640926291449425076936633178262764678572453063445218154","13941064550735375985967548290421702932981128763694428458881182266843384273940","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0"],"node_aux":{"key":"10","value":"20"}}} +{"root":"17039823904837071705763545555283546217751326723169195059364451777353741017328","proof":{"existence":false,"siblings":["14989532119404983961115670288381063073891118401716735992353404523801340288158","15817549995119513546413395894800310537308858548528902759332598606866792105384","20955911300871905860419417343337237575819647673394656670247178513070221579793","7345857457589225232320640926291449425076936633178262764678572453063445218154","13941064550735375985967548290421702932981128763694428458881182266843384273940"],"node_aux":{"key":"10","value":"20"}}} diff --git a/go.mod b/go.mod index bba61ce..61559d7 100644 --- a/go.mod +++ b/go.mod @@ -4,6 +4,7 @@ go 1.19 require ( github.com/ethereum/go-ethereum v1.12.0 + github.com/iden3/contracts-abi/onchain-credential-status-resolver/go/abi v0.0.0-20230623092404-d47a0a434f65 github.com/iden3/contracts-abi/state/go/abi v0.0.0-20230405152923-4a25f6f1f0f4 github.com/iden3/go-circuits v1.0.2 github.com/iden3/go-iden3-core v1.0.2 @@ -31,7 +32,6 @@ require ( github.com/google/uuid v1.3.0 // indirect github.com/gorilla/websocket v1.5.0 // indirect github.com/holiman/uint256 v1.2.2-0.20230321075855-87b91420868c // indirect - github.com/iden3/contracts-abi/onchain-credential-status-resolver/go/abi v0.0.0-20230623092404-d47a0a434f65 // indirect github.com/ipfs/boxo v0.8.0 // indirect github.com/ipfs/go-cid v0.4.0 // indirect github.com/klauspost/cpuid/v2 v2.2.3 // indirect diff --git a/go.sum b/go.sum index 4fffb2d..ab7f267 100644 --- a/go.sum +++ b/go.sum @@ -73,8 +73,6 @@ github.com/holiman/uint256 v1.2.2-0.20230321075855-87b91420868c h1:DZfsyhDK1hnSS github.com/holiman/uint256 v1.2.2-0.20230321075855-87b91420868c/go.mod h1:SC8Ryt4n+UBbPbIBKaG9zbbDlp4jOru9xFZmPzLUTxw= github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU= github.com/huin/goupnp v1.0.3 h1:N8No57ls+MnjlB+JPiCVSOyy/ot7MJTqlo7rn+NYSqQ= -github.com/iden3/contracts-abi/identityBase/go/abi v0.0.0-20230621153633-7549c4edaf16 h1:ZK0P87QMoUejpFAJ3egkAKj3IpSCtRRf/ztgZGcFQW4= -github.com/iden3/contracts-abi/identityBase/go/abi v0.0.0-20230621153633-7549c4edaf16/go.mod h1:VazDjFNz60ZVIZ0twlDRbW+4xp3IE+rLTbJQWSm11cQ= github.com/iden3/contracts-abi/onchain-credential-status-resolver/go/abi v0.0.0-20230623092404-d47a0a434f65 h1:K8dUsVWB2FMSK/4+Vyg3U6khNGkGFzJChJmcGNjm/KY= github.com/iden3/contracts-abi/onchain-credential-status-resolver/go/abi v0.0.0-20230623092404-d47a0a434f65/go.mod h1:8fkd2xyUG/V7ovpvZRyD2LyK2zZ4ALbgf5vJGyhzKdg= github.com/iden3/contracts-abi/state/go/abi v0.0.0-20230405152923-4a25f6f1f0f4 h1:iPvYa/AhhGo3juoUFDm/fBE2CZKy4WfQu7JY90tRf9Q= @@ -85,8 +83,6 @@ github.com/iden3/go-iden3-core v1.0.2 h1:HwNDFeqcUv4ybZj5tH+58JKWKarn/qqBpNCqTLx github.com/iden3/go-iden3-core v1.0.2/go.mod h1:X4PjlJG8OsEQEsSbzzYqqAk2olYGZ2nuGqiUPyEYjOo= github.com/iden3/go-iden3-crypto v0.0.15 h1:4MJYlrot1l31Fzlo2sF56u7EVFeHHJkxGXXZCtESgK4= github.com/iden3/go-iden3-crypto v0.0.15/go.mod h1:dLpM4vEPJ3nDHzhWFXDjzkn1qHoBeOT/3UEhXsEsP3E= -github.com/iden3/go-merkletree-sql/v2 v2.0.4 h1:Dp089P3YNX1BE8+T1tKQHWTtnk84Y/Kr7ZAGTqwscoY= -github.com/iden3/go-merkletree-sql/v2 v2.0.4/go.mod h1:kRhHKYpui5DUsry5RpveP6IC4XMe6iApdV9VChRYuEk= github.com/iden3/go-merkletree-sql/v2 v2.0.6 h1:vsVDImnvnHf7Ggr45ptFOXJyWNA/8IwVQO1jzRLUlY8= github.com/iden3/go-merkletree-sql/v2 v2.0.6/go.mod h1:kRhHKYpui5DUsry5RpveP6IC4XMe6iApdV9VChRYuEk= github.com/iden3/go-schema-processor v1.3.1 h1:LJfFInfYGMOp0bTKKC17R8q4XI+VtqhFLPTEqnOIvlM= diff --git a/proof_test.go b/proof_test.go index 14fa9ea..8b7cfe8 100644 --- a/proof_test.go +++ b/proof_test.go @@ -1,6 +1,7 @@ package c_polygonid import ( + "encoding/json" "math/big" "testing" @@ -61,3 +62,46 @@ func TestSmartContractProof_UnmarshalJSON(t *testing.T) { require.NoError(t, err) require.Equal(t, want, res) } + +func TestProofFromSmartContract(t *testing.T) { + in := `{ + "root": "17039823904837071705763545555283546217751326723169195059364451777353741017328", + "existence": false, + "siblings": [ + "14989532119404983961115670288381063073891118401716735992353404523801340288158", + "15817549995119513546413395894800310537308858548528902759332598606866792105384", + "20955911300871905860419417343337237575819647673394656670247178513070221579793", + "7345857457589225232320640926291449425076936633178262764678572453063445218154", + "13941064550735375985967548290421702932981128763694428458881182266843384273940", + "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", + "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0" + ], + "auxExistence": true, + "auxIndex": "10", + "auxValue": "20", + "index": "13625694351531357880063798347796487002182037278253017013343168668336623401886", + "value": "0" +}` + var scp SmartContractProof + err := scp.UnmarshalJSON([]byte(in)) + require.NoError(t, err) + + proof, _, err := ProofFromSmartContract(scp) + require.NoError(t, err) + + proofJson, err := json.Marshal(proof) + require.NoError(t, err) + + wantResponse := `{ + "existence": false, + "siblings": [ + "14989532119404983961115670288381063073891118401716735992353404523801340288158", + "15817549995119513546413395894800310537308858548528902759332598606866792105384", + "20955911300871905860419417343337237575819647673394656670247178513070221579793", + "7345857457589225232320640926291449425076936633178262764678572453063445218154", + "13941064550735375985967548290421702932981128763694428458881182266843384273940" + ], + "node_aux": {"key": "10", "value": "20"} +}` + require.JSONEq(t, wantResponse, string(proofJson)) +}