Skip to content

Commit f817d77

Browse files
committed
修复代码错误
1 parent 37f26ea commit f817d77

File tree

6 files changed

+33
-7
lines changed

6 files changed

+33
-7
lines changed

go.mod

+1
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,6 @@ go 1.16
44

55
require (
66
github.com/hyperledger/fabric-contract-api-go v1.1.0
7+
github.com/stretchr/testify v1.5.1
78
google.golang.org/protobuf v1.31.0
89
)

governance/user_test.go

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package governance_test
2+
3+
import (
4+
"testing"
5+
6+
"github.com/11090815/openzeppelin-go/governance"
7+
"github.com/stretchr/testify/require"
8+
)
9+
10+
func TestNewUser(t *testing.T) {
11+
user := governance.NewUser("alice")
12+
13+
serializedUser, err := user.Serialize()
14+
require.NoError(t, err)
15+
t.Log(serializedUser)
16+
17+
newUser := governance.NewUser("bob")
18+
newUser.Deserialize(serializedUser)
19+
20+
t.Log(newUser.GetUserID())
21+
}
22+
23+
func TestHello(t *testing.T) {
24+
t.Log("hello")
25+
}

governance/userlibrary.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ func (us *userStore) StoreUser(ctx contractapi.TransactionContextInterface, u Us
5858

5959
func (us *userStore) UpdateUser(ctx contractapi.TransactionContextInterface, u User) error {
6060
if oldUser, err := us.GetUser(ctx, u.GetUserID()); err != nil || oldUser == nil {
61-
return fmt.Errorf("cannot update user [%s], because this user may not exist ")
61+
return fmt.Errorf("cannot update user [%s], because this user may not exist", u.GetUserID())
6262
}
6363

6464
userBytes, err := u.Serialize()

governance/usermanager.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ func NewUser(userID string) User {
3838
return &user{
3939
User: &protos.User{
4040
Id: userID,
41-
Attrs: make(map[string]struct{}),
41+
Attrs: make(map[string][]byte),
4242
},
4343
}
4444
}
@@ -64,7 +64,7 @@ func (u *user) DelegateAttributeAuthority(attr string) error {
6464
return fmt.Errorf("user [%s] has been already delegated attribute [%s]", u.Id, attr)
6565
}
6666

67-
u.Attrs[attr] = struct{}{}
67+
u.Attrs[attr] = []byte{0x01}
6868

6969
return nil
7070
}

protos/user.pb.go

+3-3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

protos/user.proto

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,5 @@ package protos;
66

77
message User {
88
string id = 1;
9-
map<string,string> attrs = 2;
9+
map<string,bytes> attrs = 2;
1010
}

0 commit comments

Comments
 (0)