From de86c45b6fc0014d1d0a4f0f06771db804bc6004 Mon Sep 17 00:00:00 2001 From: DIGIX666 Date: Thu, 14 Nov 2024 12:12:54 +0100 Subject: [PATCH] try fix CI codecov --- .../p/demo/accesscontrol/accesscontrol.gno | 38 +++++----- .../demo/accesscontrol/accesscontrol_test.gno | 76 +++++++++---------- 2 files changed, 57 insertions(+), 57 deletions(-) diff --git a/examples/gno.land/p/demo/accesscontrol/accesscontrol.gno b/examples/gno.land/p/demo/accesscontrol/accesscontrol.gno index ed0fdec762f..8f65696b7b7 100644 --- a/examples/gno.land/p/demo/accesscontrol/accesscontrol.gno +++ b/examples/gno.land/p/demo/accesscontrol/accesscontrol.gno @@ -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 { @@ -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, @@ -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, diff --git a/examples/gno.land/p/demo/accesscontrol/accesscontrol_test.gno b/examples/gno.land/p/demo/accesscontrol/accesscontrol_test.gno index f5ba7dc64f9..e8efdf5cb1f 100644 --- a/examples/gno.land/p/demo/accesscontrol/accesscontrol_test.gno +++ b/examples/gno.land/p/demo/accesscontrol/accesscontrol_test.gno @@ -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) { @@ -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) { @@ -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 +// }