Skip to content

Commit

Permalink
fix / update unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
vmidyllic committed Jan 14, 2022
1 parent a2f30ee commit bb8e450
Show file tree
Hide file tree
Showing 3 changed files with 100 additions and 3 deletions.
97 changes: 97 additions & 0 deletions communication/auth/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -219,3 +219,100 @@ func TestVerifyMessageWithAuthProof(t *testing.T) {
assert.Equal(t, true, state.Latest)

}

func TestVerifyMessageWithAuthAndAtomicProof(t *testing.T) {

var message types.AuthorizationMessageResponse
message.Type = AuthorizationResponseMessageType
message.Data = types.AuthorizationMessageResponseData{}

zkpAuth := types.ZeroKnowledgeProof{
Type: types.ZeroKnowledgeProofType,
CircuitID: circuits.AuthCircuitID,
}

zkpAuth.ProofData = &types.ProofData{
A: []string{
"18180023362956448661504136539479880159304982705725867739071283349330504591628",
"8795654392326914098932175170738912067090297399932537425475398238807931653173",
"1"},
B: [][]string{
{
"19780465591914097068127305592306620480687677519384672775795191644424686849449",
"20515155075838074540407238257747702238898010411061896426111014073297490866516",
},
{
"9775537071673182117245376842156984770152628594742253945698670017516634175591",
"987430042765945377011935268350961990982644399277187014917044613807747388887",
},
{
"1",
"0",
}},
C: []string{
"4448068170493753728425425932647937258764981035070385065979044155276206944413",
"1924507697743532558216384088897905223212795458753055707877347972535018515365",
"1",
},
}
zkpAuth.PubSignals = []string{
"1",
"15383795261052586569047113011994713909892315748410703061728793744343300034754",
"293373448908678327289599234275657468666604586273320428510206058753616052224",
}

zkpAtomic := types.ZeroKnowledgeProof{
Type: types.ZeroKnowledgeProofType,
CircuitID: circuits.AtomicQueryCircuitID,
}

zkpAtomic.ProofData = &types.ProofData{
A: []string{
"7481603533165281782768161596089989534634372232403635534227198586269508002664",
"15712489995949740779718242057324344417884402903626312998660522973041899152652",
"1",
},
B: [][]string{
{
"19420156961726167767115741919947906779311475805065152227776305708132632001517",
"13673092530698826033441074445132606219122067435122667103437891508926774522571",
},
{
"7381275641212217541564530119836894759442882041749228350220059878720452865647",
"10828264008916120280806719134777019242457779084401504460387163519203853012622",
},
{
"1",
"0",
}},
C: []string{
"3692260483222500753746125346577585426928469576998457245838881036223205526791",
"4853027739525751459348232362683499580126387420246049550951563212732089889901",
"1",
},
}
zkpAtomic.PubSignals = []string{
"293373448908678327289599234275657468666604586273320428510206058753616052224",
"15383795261052586569047113011994713909892315748410703061728793744343300034754",
"1",
"274380136414749538182079640726762994055",
"2",
"10",
"0",
"1642074362",
}
message.Data.Scope = []interface{}{zkpAuth, zkpAtomic}

err := Verify(&message)
assert.Nil(t, err)

token, err := ExtractMetadata(&message)
assert.Nil(t, err)
assert.Equal(t, "15383795261052586569047113011994713909892315748410703061728793744343300034754", token.State)
assert.Equal(t, "11B34yHEY4tbE57kGKKFCHezo7rUBgouajFHeNszQm", token.ID)

state, err := token.VerifyState(context.Background(), os.Getenv("RPC_URL"), "0x035C4DBC897D203483D942696CE1dF5a9f933FcC")
assert.Nil(t, err)
assert.Equal(t, true, state.Latest)

}
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ go 1.17
require (
github.com/ethereum/go-ethereum v1.10.13
github.com/iden3/go-circom-prover-verifier v0.0.1
github.com/iden3/go-circuits v0.0.12
github.com/iden3/go-circuits v0.0.15
github.com/iden3/go-iden3-core v0.0.12
github.com/iden3/go-merkletree-sql v1.0.0-pre8
github.com/pkg/errors v0.9.1
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -226,8 +226,8 @@ github.com/huin/goutil v0.0.0-20170803182201-1ca381bf3150/go.mod h1:PpLOETDnJ0o3
github.com/ianlancetaylor/demangle v0.0.0-20181102032728-5e5cf60278f6/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc=
github.com/iden3/go-circom-prover-verifier v0.0.1 h1:gfmAwhvUB0Wya++dGfgvMYPsLzJf34Yw6x269CnhOP0=
github.com/iden3/go-circom-prover-verifier v0.0.1/go.mod h1:1FkpX4nUXxYcY2fpzqd27wHHEnWeo1v1nwDnz2TgBRo=
github.com/iden3/go-circuits v0.0.12 h1:jlECju6vAxXYJXG33NwiVkYZSCe8W/pOuXfyj4QLyl4=
github.com/iden3/go-circuits v0.0.12/go.mod h1:7zat5ks5thTadVZT/FlPFEr51x58kxBqvEpMpH7x+eQ=
github.com/iden3/go-circuits v0.0.15 h1:YA+rQbulvn0aWn3PigYGVkjcILMXW2llvWIIhV6tVbM=
github.com/iden3/go-circuits v0.0.15/go.mod h1:7zat5ks5thTadVZT/FlPFEr51x58kxBqvEpMpH7x+eQ=
github.com/iden3/go-iden3-core v0.0.12 h1:wmDZU2e5Z7iMrCUCQQWzeUqBE8X4wl3t41DeyhnHpL8=
github.com/iden3/go-iden3-core v0.0.12/go.mod h1:Ou51YR716WqeBJ3Z4BkGVAJROgSYgfnl4i8x3mfLOeY=
github.com/iden3/go-iden3-crypto v0.0.5/go.mod h1:XKw1oDwYn2CIxKOtr7m/mL5jMn4mLOxAxtZBRxQBev8=
Expand Down

0 comments on commit bb8e450

Please sign in to comment.