Skip to content

Commit 03b2db9

Browse files
committed
Refactor grant roles test
1 parent 3cd0e27 commit 03b2db9

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

tests/grant_roles.test.js

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ const { describe } = require('yargs')
88
const server = "http://127.0.0.1"
99
const port = 8080
1010

11-
var adminAccount, receiverAccount, token, clientV2, appId
11+
var adminAccount, receiverAccount, token, clientV2, appId, localState
1212

1313
beforeEach(async () => {
1414
await privateTestNetSetup(appId)
@@ -23,17 +23,23 @@ beforeEach(async () => {
2323
await util.optInApp(clientV2, receiverAccount, appId)
2424
})
2525

26-
test('contract admin role can be granted by contract admin', async () => {
26+
async function grantRoles(roleId, from=adminAccount, target=receiverAccount) {
2727
appArgs = [
2828
EncodeBytes("grantRoles"),
29-
EncodeUint('8')
29+
EncodeUint(roleId)
3030
]
31-
await util.appCall(clientV2, adminAccount, appId, appArgs, [receiverAccount.addr])
31+
await util.appCall(clientV2, from, appId, appArgs, [target.addr])
32+
}
33+
34+
test('contract admin role can be granted by contract admin', async () => {
35+
await grantRoles(8, adminAccount, receiverAccount)
3236

3337
localState = await util.readLocalState(clientV2, receiverAccount, appId)
3438
expect(localState["roles"]["ui"]).toEqual(8)
3539

36-
await util.appCall(clientV2, receiverAccount, appId, appArgs, [receiverAccount.addr])
40+
await grantRoles(15, receiverAccount, receiverAccount)
41+
localState = await util.readLocalState(clientV2, receiverAccount, appId)
42+
expect(localState["roles"]["ui"]).toEqual(15)
3743
})
3844

3945
test('contract admin role can be revoked by contract admin', async () => {

0 commit comments

Comments
 (0)