Skip to content

Commit

Permalink
update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
findolor committed Jan 24, 2025
1 parent f18ed1f commit ef8e833
Showing 1 changed file with 85 additions and 2 deletions.
87 changes: 85 additions & 2 deletions packages/orderbook/test/js_api/vault.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ import {
getVault,
getVaultBalanceChanges,
getVaultDepositCalldata,
getVaultWithdrawCalldata
getVaultWithdrawCalldata,
checkVaultAllowance,
getVaultApprovalCalldata
} from '../../dist/cjs/js_api.js';

const vault1: Vault = {
Expand Down Expand Up @@ -181,7 +183,7 @@ describe('Rain Orderbook JS API Package Bindgen Vault Tests', async function ()
symbol: 'T1',
decimals: '0'
},
balance: '0',
balance: '88888888888',
vaultId: '0x2523',
owner: '0x0000000000000000000000000000000000000000',
ordersAsOutput: [],
Expand Down Expand Up @@ -283,4 +285,85 @@ describe('Rain Orderbook JS API Package Bindgen Vault Tests', async function ()
assert.equal((error as Error).message, 'Invalid amount');
}
});

it('should read allowance for a vault', async () => {
await mockServer.forPost('/sg4').thenReply(200, JSON.stringify({ data: { order } }));
await mockServer
.forPost('/sg4')
.once()
.thenSendJsonRpcResult('0x0000000000000000000000000000000000000000000000000000000000000001');

let allowance: string = await checkVaultAllowance(mockServer.url + '/sg4', 'order1', 0);
assert.equal(allowance, '0x1');

try {
await checkVaultAllowance(mockServer.url + '/sg4', 'order1', 99);
assert.fail('expected to reject, but resolved');
} catch (e) {
assert.equal((e as Error).message, 'Invalid input index');
}
});

it('should get approval calldata for a vault', async () => {
await mockServer
.forPost('/sg4')
.once()
.thenReply(200, JSON.stringify({ data: { order } }));
await mockServer
.forPost('/sg4')
.once()
.thenSendJsonRpcResult('0x00000000000000000000000000000000000000000000000000000000000001f4');

let calldata: string = await getVaultApprovalCalldata(
mockServer.url + '/sg4',
'order1',
0,
'600'
);
assert.equal(calldata.length, 138);

await mockServer
.forPost('/sg4')
.once()
.thenReply(200, JSON.stringify({ data: { order } }));
await mockServer
.forPost('/sg4')
.once()
.thenSendJsonRpcResult('0x00000000000000000000000000000000000000000000000000000000000001f4');

calldata = await getVaultApprovalCalldata(mockServer.url + '/sg4', 'order1', 0, '500');
assert.equal(calldata.length, 138);

await mockServer.forPost('/sg4').thenReply(200, JSON.stringify({ data: { order } }));

try {
await getVaultApprovalCalldata(mockServer.url + '/sg4', 'order1', 0, '0');
assert.fail('expected to reject, but resolved');
} catch (e) {
assert.equal((e as Error).message, 'Invalid amount');
}

try {
await getVaultApprovalCalldata(mockServer.url + '/sg4', 'order1', 99, '500');
assert.fail('expected to reject, but resolved');
} catch (e) {
assert.equal((e as Error).message, 'Invalid input index');
}

await mockServer
.forPost('/sg4')
.once()
.thenReply(200, JSON.stringify({ data: { order } }));
await mockServer
.forPost('/sg4')
.once()
.thenSendJsonRpcResult('0x00000000000000000000000000000000000000000000000000000000000001f4');

try {
await getVaultApprovalCalldata(mockServer.url + '/sg4', 'order1', 0, '200');
assert.fail('expected to reject, but resolved');
} catch (e) {
assert.equal((e as Error).message, 'Invalid amount');
}
});
});

0 comments on commit ef8e833

Please sign in to comment.