Skip to content

Commit 3cd0e27

Browse files
committed
Test that transferRules for transferGroup 0 work fine.
1 parent caca0ac commit 3cd0e27

File tree

1 file changed

+95
-19
lines changed

1 file changed

+95
-19
lines changed

tests/transfer_restrictions.test.js

Lines changed: 95 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,25 @@ test('has expected starting test state', async () => {
4848
expect(localState["transfer admin"]).toEqual(undefined)
4949
})
5050

51-
test('simple transfer', async () => {
51+
test('cannot transfer by default from and to the default group 1 -> 1', async () => {
52+
try {
53+
appArgs = [EncodeBytes("transfer"), EncodeUint('11')]
54+
await util.appCall(clientV2, adminAccount, appId, appArgs, [receiverAccount.addr])
55+
} catch (e) {
56+
expect(e.message).toEqual("Bad Request")
57+
}
58+
// check first receiver got no tokens and is in group 1
59+
let localState = await util.readLocalState(clientV2, receiverAccount, appId)
60+
expect(localState["transferGroup"]["ui"]).toEqual(1)
61+
expect(localState["balance"]["ui"]).toEqual(undefined)
62+
63+
// check sender sent no tokens and is in group 1
64+
localState = await util.readLocalState(clientV2, adminAccount, appId)
65+
expect(localState["transferGroup"]["ui"]).toEqual(1)
66+
expect(localState["balance"]["ui"]).toEqual(27)
67+
})
68+
69+
test('simple transfer back and forth: with group 1 -> 1 permitted', async () => {
5270
let fromGroupId = 1
5371
let toGroupId = 1
5472
let earliestPermittedTime = 1
@@ -80,6 +98,24 @@ test('simple transfer', async () => {
8098
globalState = await util.readGlobalState(clientV2, adminAccount, appId)
8199
expect(globalState['cap']['ui'].toString()).toEqual('80000000000000000')
82100
expect(globalState['reserve']['ui'].toString()).toEqual('79999999999999973')
101+
102+
// ======
103+
//transfer back
104+
appArgs = [EncodeBytes("transfer"), EncodeUint('11')]
105+
await util.appCall(clientV2, receiverAccount, appId, appArgs, [adminAccount.addr])
106+
107+
// check original sender got tokens back
108+
localState = await util.readLocalState(clientV2, adminAccount, appId)
109+
expect(localState["balance"]["ui"]).toEqual(27)
110+
111+
// check tokens deducted
112+
localState = await util.readLocalState(clientV2, receiverAccount, appId)
113+
expect(localState["balance"]["ui"]).toEqual(undefined)
114+
115+
// check global supply is same
116+
globalState = await util.readGlobalState(clientV2, adminAccount, appId)
117+
expect(globalState['cap']['ui'].toString()).toEqual('80000000000000000')
118+
expect(globalState['reserve']['ui'].toString()).toEqual('79999999999999973')
83119
})
84120

85121
test('can lock the default address category for transfers', async () => {
@@ -107,6 +143,64 @@ test('can lock the default address category for transfers', async () => {
107143
expect(localState["balance"]["ui"]).toEqual(undefined)
108144
})
109145

146+
test('simple transfer from group 0 -> 0 works when permitted', async () => {
147+
let fromGroupId = 0
148+
let toGroupId = 0
149+
let earliestPermittedTime = 1
150+
151+
let transferGroupLock =
152+
`goal app call --app-id ${appId} --from ${adminAccount.addr} ` +
153+
`--app-arg 'str:setTransferRule' ` +
154+
`--app-arg "int:${fromGroupId}" --app-arg "int:${toGroupId}" ` +
155+
`--app-arg "int:${earliestPermittedTime}" -d devnet/Primary`
156+
157+
appArgs = [EncodeBytes("setAddressPermissions"), EncodeUint('0'), EncodeUint('0'), EncodeUint('0'), EncodeUint('0')]
158+
await util.appCall(clientV2, adminAccount, appId, appArgs, [adminAccount.addr])
159+
await util.appCall(clientV2, adminAccount, appId, appArgs, [receiverAccount.addr])
160+
161+
await shell.exec(transferGroupLock, {async: false, silent: false})
162+
163+
globalState = await util.readGlobalState(clientV2, adminAccount, appId)
164+
expect(globalState['reserve']['ui'].toString()).toEqual('79999999999999973')
165+
166+
//transfer
167+
appArgs = [EncodeBytes("transfer"), EncodeUint('11')]
168+
await util.appCall(clientV2, adminAccount, appId, appArgs, [receiverAccount.addr])
169+
170+
// check receiver got tokens
171+
localState = await util.readLocalState(clientV2, receiverAccount, appId)
172+
expect(localState["balance"]["ui"]).toEqual(11)
173+
expect(localState["transferGroup"]["ui"]).toEqual(undefined)
174+
175+
// check sender has less tokens
176+
localState = await util.readLocalState(clientV2, adminAccount, appId)
177+
expect(localState["balance"]["ui"]).toEqual(16)
178+
expect(localState["transferGroup"]["ui"]).toEqual(undefined)
179+
180+
// check global supply is same
181+
globalState = await util.readGlobalState(clientV2, adminAccount, appId)
182+
expect(globalState['cap']['ui'].toString()).toEqual('80000000000000000')
183+
expect(globalState['reserve']['ui'].toString()).toEqual('79999999999999973')
184+
185+
// ======
186+
//transfer back
187+
appArgs = [EncodeBytes("transfer"), EncodeUint('11')]
188+
await util.appCall(clientV2, receiverAccount, appId, appArgs, [adminAccount.addr])
189+
190+
// check original sender got tokens back
191+
localState = await util.readLocalState(clientV2, adminAccount, appId)
192+
expect(localState["balance"]["ui"]).toEqual(27)
193+
194+
// check tokens deducted
195+
localState = await util.readLocalState(clientV2, receiverAccount, appId)
196+
expect(localState["balance"]["ui"]).toEqual(undefined)
197+
198+
// check global supply is same
199+
globalState = await util.readGlobalState(clientV2, adminAccount, appId)
200+
expect(globalState['cap']['ui'].toString()).toEqual('80000000000000000')
201+
expect(globalState['reserve']['ui'].toString()).toEqual('79999999999999973')
202+
})
203+
110204
test('can transfer to an account if the transfer rule lock has expired', async () => {
111205
let fromGroupId = 1
112206
let toGroupId = 1
@@ -128,24 +222,6 @@ test('can transfer to an account if the transfer rule lock has expired', async (
128222
expect(localState["balance"]["ui"]).toEqual(11)
129223
})
130224

131-
test('cannot transfer by default from and to the default group 1', async () => {
132-
try {
133-
appArgs = [EncodeBytes("transfer"), EncodeUint('11')]
134-
await util.appCall(clientV2, adminAccount, appId, appArgs, [receiverAccount.addr])
135-
} catch (e) {
136-
expect(e.message).toEqual("Bad Request")
137-
}
138-
// check first receiver got no tokens and is in group 1
139-
let localState = await util.readLocalState(clientV2, receiverAccount, appId)
140-
expect(localState["transferGroup"]["ui"]).toEqual(1)
141-
expect(localState["balance"]["ui"]).toEqual(undefined)
142-
143-
// check sender sent no tokens and is in group 1
144-
localState = await util.readLocalState(clientV2, adminAccount, appId)
145-
expect(localState["transferGroup"]["ui"]).toEqual(1)
146-
expect(localState["balance"]["ui"]).toEqual(27)
147-
})
148-
149225
test('can transfer between permitted account groups', async () => {
150226
let earliestPermittedTime = 1
151227
// from group 1 -> 1 is allowed

0 commit comments

Comments
 (0)