Skip to content

Commit

Permalink
chore: lint
Browse files Browse the repository at this point in the history
  • Loading branch information
andy-haynes committed Aug 20, 2024
1 parent 86363ca commit 015c916
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,42 +9,42 @@ const ACCOUNT_ID = 'accountid';
const CONTRACT_ID = 'contractid';
const KEYPAIR = new KeyPairEd25519('2wyRcSwSuHtRVmkMCGjPwnzZmQLeXLzLLyED1NDMt4BjnKgQL6tF85yBx6Jr26D2dUNeC716RBoTxntVHsegogYw');

let ctx = {
const ctx = {
keyStore: new MultiContractBrowserLocalStorageKeyStore(LocalStorageMemory)
}
};

beforeEach(async () => {
await ctx.keyStore.clear();
await ctx.keyStore.setKey(NETWORK_ID, ACCOUNT_ID, KEYPAIR, CONTRACT_ID);
await ctx.keyStore.clear();
await ctx.keyStore.setKey(NETWORK_ID, ACCOUNT_ID, KEYPAIR, CONTRACT_ID);
});

test('Get not-existing account', async () => {
expect(await ctx.keyStore.getKey('somenetwork', 'someaccount', 'somecontract')).toBeNull();
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);
const key = await ctx.keyStore.getKey(NETWORK_ID, ACCOUNT_ID, CONTRACT_ID);
expect(key).toEqual(KEYPAIR);
});

test('Get contracts', async () => {
const contracts = await ctx.keyStore.getContracts(NETWORK_ID, ACCOUNT_ID);
expect(contracts).toEqual([CONTRACT_ID]);
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]);
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]);
});
3 changes: 0 additions & 3 deletions packages/near-api-js/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,6 @@
"test": "jest --passWithNoTests",
"lint": "concurrently \"pnpm:lint:*(!fix) --no-error-on-unmatched-pattern\"",
"lint:src": "eslint --ext .ts src",
"lint:fix": "concurrently \"pnpm:lint:*:fix\"",
"lint:src:fix": "eslint --ext .ts --fix src",
"lint:test:fix": "eslint --ext .js --fix test",
"prefuzz": "pnpm build",
"fuzz": "jsfuzz test/fuzz/borsh-roundtrip.js test/fuzz/corpus/",
"clean": "pnpm rimraf lib",
Expand Down

0 comments on commit 015c916

Please sign in to comment.