MCPcopy Create free account
hub / github.com/DNAProject/DNA / CaseController

Function CaseController

smartcontract/service/native/did/controller_test.go:43–204  ·  view source on GitHub ↗

Test case: register an ID controlled by another ID

(t *testing.T, n *native.NativeService)

Source from the content-addressed store, hash-verified

41
42// Test case: register an ID controlled by another ID
43func CaseController(t *testing.T, n *native.NativeService) {
44 a0 := account.NewAccount("")
45 id0, _ := account.GenerateID()
46 id1, _ := account.GenerateID()
47
48 // 1. unregistered controller, should fail
49 if err := regControlledID(n, id1, id0, 1, a0.Address); err == nil {
50 t.Error("registered controlled id with unregistered controller")
51 }
52
53 // 2. register the controller
54 if err := regID(n, id0, a0); err != nil {
55 t.Fatal(err)
56 }
57
58 // 3. register without valid signature, should fail
59 if err := regControlledID(n, id1, id0, 1, common.ADDRESS_EMPTY); err == nil {
60 t.Error("registered without valid signature")
61 }
62
63 // 4. register with invalid key index, should fail
64 if err := regControlledID(n, id1, id0, 2, a0.Address); err == nil {
65 t.Error("registered with invalid key index")
66 }
67
68 // 5. register with invalid id, should fail
69 if err := regControlledID(n, "did:dna::123", id0, 1, a0.Address); err == nil {
70 t.Error("invalid id registered")
71 }
72
73 // 6. register the controlled ID
74 if err := regControlledID(n, id1, id0, 1, a0.Address); err != nil {
75 t.Fatal(err)
76 }
77
78 // 7. register again, should fail
79 if err := regControlledID(n, id1, id0, 1, a0.Address); err == nil {
80 t.Fatal("register twice")
81 }
82
83 // 8. verify controller
84 if ok, err := verifyCtrl(n, id1, 1, a0.Address); !ok || err != nil {
85 t.Fatal("verify controller error", err)
86 }
87
88 // 9. verify invalid controller, should fail
89 if ok, err := verifyCtrl(n, id1, 2, a0.Address); ok && err == nil {
90 t.Error("invalid controller key index passed verification")
91 }
92
93 // 10. verify controller without valid signature, should fail
94 if ok, err := verifyCtrl(n, id1, 1, common.ADDRESS_EMPTY); ok && err == nil {
95 t.Error("controller passed verification without valid signature")
96 }
97
98 // 11. add attribute by invalid controller, should fail
99 attr := attribute{
100 []byte("test key"),

Callers

nothing calls this directly

Calls 14

PubKeyMethod · 0.95
NewAccountFunction · 0.92
GenerateIDFunction · 0.92
regControlledIDFunction · 0.85
regIDFunction · 0.85
verifyCtrlFunction · 0.85
ctrlAddAttrFunction · 0.85
checkAttributeFunction · 0.85
ctrlRmAttrFunction · 0.85
ctrlAddKeyFunction · 0.85
ctrlRmKeyFunction · 0.85
rmCtrlFunction · 0.85

Tested by

no test coverage detected