Skip to content

Commit

Permalink
try fix CI codecov
Browse files Browse the repository at this point in the history
  • Loading branch information
DIGIX666 committed Nov 14, 2024
1 parent 13f8de4 commit de86c45
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 57 deletions.
38 changes: 19 additions & 19 deletions examples/gno.land/p/demo/accesscontrol/accesscontrol.gno
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ type Role struct {

// Roles struct to store all Roles information
type Roles struct {
Roles []*Role
UserToRoles avl.Tree // std.Address -> []*Role
Ownable *ownable.Ownable
Roles []*Role
// UserToRoles avl.Tree // std.Address -> []*Role
Ownable *ownable.Ownable
}

func validRoleName(name string) error {
Expand Down Expand Up @@ -112,12 +112,12 @@ func (rs *Roles) GrantRole(name string, account std.Address) error {
r.Holders.Set(account.String(), struct{}{})

// Add in UserToRoles
roles, found := rs.UserToRoles.Get(account.String())
if !found {
roles = []*Role{}
}
roles = append(roles.([]*Role), r)
rs.UserToRoles.Set(account.String(), roles)
// roles, found := rs.UserToRoles.Get(account.String())
// if !found {
// roles = []*Role{}
// }
// roles = append(roles.([]*Role), r)
// rs.UserToRoles.Set(account.String(), roles)

std.Emit(
RoleGrantedEvent,
Expand All @@ -144,16 +144,16 @@ func (rs *Roles) RevokeRole(name string, account std.Address) error {
r.Holders.Remove(account.String())

// Remove in UserToRoles
roles, found := rs.UserToRoles.Get(account.String())
if found {
updatedRoles := []*Role{}
for _, role := range roles.([]*Role) {
if role != r {
updatedRoles = append(updatedRoles, role)
}
}
rs.UserToRoles.Set(account.String(), updatedRoles)
}
// roles, found := rs.UserToRoles.Get(account.String())
// if found {
// updatedRoles := []*Role{}
// for _, role := range roles.([]*Role) {
// if role != r {
// updatedRoles = append(updatedRoles, role)
// }
// }
// rs.UserToRoles.Set(account.String(), updatedRoles)
// }

std.Emit(
RoleRevokedEvent,
Expand Down
76 changes: 38 additions & 38 deletions examples/gno.land/p/demo/accesscontrol/accesscontrol_test.gno
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,9 @@ func TestGrantRole(t *testing.T) {
uassert.NoError(t, err)
uassert.True(t, role.HasAccount(user1), "user1 should have the TestRole")

rolesList, found := roles.UserToRoles.Get(user1.String())
uassert.True(t, found, "user1 should be in UserToRoles")
uassert.True(t, containsRole(rolesList.([]*Role), role), "UserToRoles should contain TestRole for user1")
// rolesList, found := roles.UserToRoles.Get(user1.String())
// uassert.True(t, found, "user1 should be in UserToRoles")
// uassert.True(t, containsRole(rolesList.([]*Role), role), "UserToRoles should contain TestRole for user1")
}

func TestGrantRoleByNonOwner(t *testing.T) {
Expand Down Expand Up @@ -91,10 +91,10 @@ func TestRevokeRole(t *testing.T) {
uassert.NoError(t, err)
uassert.False(t, role.HasAccount(user1), "user1 should no longer have the TestRole")

rolesList, found := roles.UserToRoles.Get(user1.String())
if found {
uassert.False(t, containsRole(rolesList.([]*Role), role), "UserToRoles should not contain TestRole for user1 after revocation")
}
// rolesList, found := roles.UserToRoles.Get(user1.String())
// if found {
// uassert.False(t, containsRole(rolesList.([]*Role), role), "UserToRoles should not contain TestRole for user1 after revocation")
// }
}

func TestRenounceRole(t *testing.T) {
Expand Down Expand Up @@ -203,41 +203,41 @@ func TestDeleteRole(t *testing.T) {
uassert.Error(t, err, "should fail when trying to find deleted role")
}

func TestUserToRolesWithMultipleRoles(t *testing.T) {
roles := initSetup(admin)
// func TestUserToRolesWithMultipleRoles(t *testing.T) {
// roles := initSetup(admin)

std.TestSetOrigCaller(admin)
// std.TestSetOrigCaller(admin)

roleName1 := "Role1"
roleName2 := "Role2"
// roleName1 := "Role1"
// roleName2 := "Role2"

// Créer deux rôles
_, err := roles.CreateRole(roleName1)
uassert.NoError(t, err)
_, err = roles.CreateRole(roleName2)
uassert.NoError(t, err)
// // Create two roles
// _, err := roles.CreateRole(roleName1)
// uassert.NoError(t, err)
// _, err = roles.CreateRole(roleName2)
// uassert.NoError(t, err)

// Accorder les deux rôles à user1
err = roles.GrantRole(roleName1, user1)
uassert.NoError(t, err)
err = roles.GrantRole(roleName2, user1)
uassert.NoError(t, err)
// // Grant both roles to user1
// err = roles.GrantRole(roleName1, user1)
// uassert.NoError(t, err)
// err = roles.GrantRole(roleName2, user1)
// uassert.NoError(t, err)

// Vérifier que UserToRoles contient les deux rôles pour user1
rolesList, found := roles.UserToRoles.Get(user1.String())
uassert.True(t, found, "user1 should be in UserToRoles")
role1, _ := roles.FindRole(roleName1)
role2, _ := roles.FindRole(roleName2)
uassert.True(t, containsRole(rolesList.([]*Role), role1), "UserToRoles should contain Role1 for user1")
uassert.True(t, containsRole(rolesList.([]*Role), role2), "UserToRoles should contain Role2 for user1")
}
// // Check if user1 has both roles
// rolesList, found := roles.UserToRoles.Get(user1.String())
// uassert.True(t, found, "user1 should be in UserToRoles")
// role1, _ := roles.FindRole(roleName1)
// role2, _ := roles.FindRole(roleName2)
// uassert.True(t, containsRole(rolesList.([]*Role), role1), "UserToRoles should contain Role1 for user1")
// uassert.True(t, containsRole(rolesList.([]*Role), role2), "UserToRoles should contain Role2 for user1")
// }

// func test for check if a role is in a list of roles
func containsRole(roles []*Role, target *Role) bool {
for _, role := range roles {
if role == target {
return true
}
}
return false
}
// func containsRole(roles []*Role, target *Role) bool {
// for _, role := range roles {
// if role == target {
// return true
// }
// }
// return false
// }

0 comments on commit de86c45

Please sign in to comment.