-
Notifications
You must be signed in to change notification settings - Fork 247
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add multi_contract_keystore tests
- Loading branch information
Showing
3 changed files
with
82 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
--- | ||
"@near-js/keystores": minor | ||
"@near-js/keystores-browser": minor | ||
--- | ||
|
||
Add multi_contract_keystore |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
64 changes: 64 additions & 0 deletions
64
packages/keystores-browser/test/multi_contract_browser_keystore_common.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
const { KeyPairEd25519 } = require('@near-js/crypto'); | ||
|
||
const NETWORK_ID = 'networkid'; | ||
const ACCOUNT_ID = 'accountid'; | ||
const CONTRACT_ID = 'contractid'; | ||
const KEYPAIR = new KeyPairEd25519('2wyRcSwSuHtRVmkMCGjPwnzZmQLeXLzLLyED1NDMt4BjnKgQL6tF85yBx6Jr26D2dUNeC716RBoTxntVHsegogYw'); | ||
|
||
module.exports.shouldStoreAndRetrieveKeys = ctx => { | ||
beforeEach(async () => { | ||
await ctx.keyStore.clear(); | ||
await ctx.keyStore.setKey(NETWORK_ID, ACCOUNT_ID, KEYPAIR, CONTRACT_ID); | ||
}); | ||
|
||
test('Get all keys with empty network returns empty list', async () => { | ||
const emptyList = await ctx.keyStore.getAccounts('emptynetwork'); | ||
expect(emptyList).toEqual([]); | ||
}); | ||
|
||
test('Get all keys with single key in keystore', async () => { | ||
const accountIds = await ctx.keyStore.getAccounts(NETWORK_ID); | ||
expect(accountIds).toEqual([ACCOUNT_ID]); | ||
}); | ||
|
||
test('Get not-existing account', async () => { | ||
expect(await ctx.keyStore.getKey('somenetwork', 'someaccount', 'somecontract')).toBeNull(); | ||
}); | ||
|
||
test('Get account id from a network with single key', async () => { | ||
const key = await ctx.keyStore.getKey(NETWORK_ID, ACCOUNT_ID, CONTRACT_ID); | ||
expect(key).toEqual(KEYPAIR); | ||
}); | ||
|
||
test('Get networks', async () => { | ||
const networks = await ctx.keyStore.getNetworks(); | ||
expect(networks).toEqual([NETWORK_ID]); | ||
}); | ||
|
||
test('Get accounts', async () => { | ||
const accounts = await ctx.keyStore.getAccounts(NETWORK_ID); | ||
expect(accounts).toEqual([ACCOUNT_ID]); | ||
}); | ||
|
||
test('Get contracts', async () => { | ||
const contracts = await ctx.keyStore.getContracts(NETWORK_ID, ACCOUNT_ID); | ||
expect(contracts).toEqual([CONTRACT_ID]); | ||
}); | ||
|
||
test('Add two contracts to account and retrieve them', async () => { | ||
const networkId = "network" | ||
const accountId = "account" | ||
const contract1 = "contract1" | ||
const contract2 = "contract2" | ||
const key1Expected = KeyPairEd25519.fromRandom(); | ||
const key2Expected = KeyPairEd25519.fromRandom(); | ||
await ctx.keyStore.setKey(networkId, accountId, key1Expected, contract1); | ||
await ctx.keyStore.setKey(networkId, accountId, key2Expected, contract2); | ||
const key1 = await ctx.keyStore.getKey(networkId, accountId, contract1); | ||
const key2 = await ctx.keyStore.getKey(networkId, accountId, contract2); | ||
expect(key1).toEqual(key1Expected); | ||
expect(key2).toEqual(key2Expected); | ||
const contractIds = await ctx.keyStore.getContracts(networkId, accountId); | ||
expect(contractIds).toEqual([contract1, contract2]); | ||
}); | ||
}; |