44 "iter"
55 "testing"
66
7+ "github.com/MetaMask/go-did-it"
78 "github.com/MetaMask/go-did-it/didtest"
9+ "github.com/ipfs/go-cid"
810 "github.com/stretchr/testify/require"
911
1012 "github.com/ucan-wg/go-ucan/pkg/command"
@@ -23,17 +25,76 @@ func TestFindProof(t *testing.T) {
2325 }
2426 }
2527
26- require .Equal (t , delegationtest .ProofAliceBob ,
27- FindProof (dlgs , didtest .PersonaBob .DID (), delegationtest .NominalCommand , didtest .PersonaAlice .DID ()))
28- require .Equal (t , delegationtest .ProofAliceBobCarol ,
29- FindProof (dlgs , didtest .PersonaCarol .DID (), delegationtest .NominalCommand , didtest .PersonaAlice .DID ()))
30- require .Equal (t , delegationtest .ProofAliceBobCarolDan ,
31- FindProof (dlgs , didtest .PersonaDan .DID (), delegationtest .NominalCommand , didtest .PersonaAlice .DID ()))
32- require .Equal (t , delegationtest .ProofAliceBobCarolDanErin ,
33- FindProof (dlgs , didtest .PersonaErin .DID (), delegationtest .NominalCommand , didtest .PersonaAlice .DID ()))
34- require .Equal (t , delegationtest .ProofAliceBobCarolDanErinFrank ,
35- FindProof (dlgs , didtest .PersonaFrank .DID (), delegationtest .NominalCommand , didtest .PersonaAlice .DID ()))
28+ for _ , tc := range []struct {
29+ name string
30+ issuer did.DID
31+ command command.Command
32+ subject did.DID
33+ expected []cid.Cid
34+ }{
35+ // Passes
36+ {
37+ name : "Alice --> Alice (self-delegation)" ,
38+ issuer : didtest .PersonaAlice .DID (),
39+ command : delegationtest .NominalCommand ,
40+ subject : didtest .PersonaAlice .DID (),
41+ expected : []cid.Cid {delegationtest .TokenAliceAliceCID },
42+ },
43+ {
44+ name : "Alice --> Bob" ,
45+ issuer : didtest .PersonaBob .DID (),
46+ command : delegationtest .NominalCommand ,
47+ subject : didtest .PersonaAlice .DID (),
48+ expected : delegationtest .ProofAliceBob ,
49+ },
50+ {
51+ name : "Alice --> Bob --> Carol" ,
52+ issuer : didtest .PersonaCarol .DID (),
53+ command : delegationtest .NominalCommand ,
54+ subject : didtest .PersonaAlice .DID (),
55+ expected : delegationtest .ProofAliceBobCarol ,
56+ },
57+ {
58+ name : "Alice --> Bob --> Carol --> Dan" ,
59+ issuer : didtest .PersonaDan .DID (),
60+ command : delegationtest .NominalCommand ,
61+ subject : didtest .PersonaAlice .DID (),
62+ expected : delegationtest .ProofAliceBobCarolDan ,
63+ },
64+ {
65+ name : "Alice --> Bob --> Carol --> Dan --> Erin" ,
66+ issuer : didtest .PersonaErin .DID (),
67+ command : delegationtest .NominalCommand ,
68+ subject : didtest .PersonaAlice .DID (),
69+ expected : delegationtest .ProofAliceBobCarolDanErin ,
70+ },
71+ {
72+ name : "Alice --> Bob --> Carol --> Dan --> Erin --> Frank" ,
73+ issuer : didtest .PersonaFrank .DID (),
74+ command : delegationtest .NominalCommand ,
75+ subject : didtest .PersonaAlice .DID (),
76+ expected : delegationtest .ProofAliceBobCarolDanErinFrank ,
77+ },
3678
37- // wrong command
38- require .Empty (t , FindProof (dlgs , didtest .PersonaBob .DID (), command .New ("foo" ), didtest .PersonaAlice .DID ()))
79+ // Fails
80+ {
81+ name : "wrong command" ,
82+ issuer : didtest .PersonaBob .DID (),
83+ command : command .New ("foo" ),
84+ subject : didtest .PersonaAlice .DID (),
85+ expected : nil ,
86+ },
87+ {
88+ name : "wrong subject" ,
89+ issuer : didtest .PersonaBob .DID (),
90+ command : delegationtest .NominalCommand ,
91+ subject : didtest .PersonaDan .DID (),
92+ expected : nil ,
93+ },
94+ } {
95+ t .Run (tc .name , func (t * testing.T ) {
96+ res := FindProof (dlgs , tc .issuer , tc .command , tc .subject )
97+ require .Equal (t , tc .expected , res )
98+ })
99+ }
39100}
0 commit comments