Skip to content

Commit

Permalink
Change test setup to use account helper if available
Browse files Browse the repository at this point in the history
  • Loading branch information
vgrichina committed Apr 14, 2020
1 parent b7e3452 commit ed354a2
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 13 deletions.
4 changes: 2 additions & 2 deletions test/account.access_key.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ jasmine.DEFAULT_TIMEOUT_INTERVAL = 50000;

beforeAll(async () => {
nearjs = await testUtils.setUpTestConnection();
testAccount = await testUtils.createAccount(await nearjs.account(testUtils.testAccountName), { amount: testUtils.INITIAL_BALANCE.mul(new BN(100)) });
testAccount = await testUtils.createAccount(nearjs, { amount: testUtils.INITIAL_BALANCE.mul(new BN(100)) });
});

beforeEach(async () => {
contractId = testUtils.generateUniqueString('test');
workingAccount = await testUtils.createAccount(testAccount);
workingAccount = await testUtils.createAccount(nearjs);
contract = await testUtils.deployContract(workingAccount, contractId);
});

Expand Down
10 changes: 5 additions & 5 deletions test/account.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jasmine.DEFAULT_TIMEOUT_INTERVAL = 50000;

beforeAll(async () => {
nearjs = await testUtils.setUpTestConnection();
workingAccount = await testUtils.createAccount(await nearjs.account(testUtils.testAccountName), { amount: testUtils.INITIAL_BALANCE.mul(new BN(100)) });
workingAccount = await testUtils.createAccount(nearjs, { amount: testUtils.INITIAL_BALANCE.mul(new BN(100)) });
let nodeStatus = await nearjs.connection.provider.status();
startFromVersion = (version) => semver.gte(nodeStatus.version.version, version);
});
Expand All @@ -35,17 +35,17 @@ test('create account and then view account returns the created account', async (
});

test('send money', async() => {
const sender = await testUtils.createAccount(workingAccount);
const receiver = await testUtils.createAccount(workingAccount);
const sender = await testUtils.createAccount(nearjs);
const receiver = await testUtils.createAccount(nearjs);
await sender.sendMoney(receiver.accountId, new BN(10000));
await receiver.fetchState();
const state = await receiver.state();
expect(state.amount).toEqual(testUtils.INITIAL_BALANCE.add(new BN(10000)).toString());
});

test('delete account', async() => {
const sender = await testUtils.createAccount(workingAccount);
const receiver = await testUtils.createAccount(workingAccount);
const sender = await testUtils.createAccount(nearjs);
const receiver = await testUtils.createAccount(nearjs);
await sender.deleteAccount(receiver.accountId);
const reloaded = new nearApi.Account(sender.connection, sender);
await expect(reloaded.state()).rejects.toThrow();
Expand Down
2 changes: 1 addition & 1 deletion test/promise.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const CONTRACT_CALL_GAS = new BN(300000000000000);

beforeAll(async () => {
nearjs = await testUtils.setUpTestConnection();
workingAccount = await testUtils.createAccount(await nearjs.account(testUtils.testAccountName), { amount: testUtils.INITIAL_BALANCE.mul(new BN(100)) });
workingAccount = await testUtils.createAccount(nearjs, { amount: testUtils.INITIAL_BALANCE.mul(new BN(100)) });
});

describe('with promises', () => {
Expand Down
9 changes: 4 additions & 5 deletions test/test-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,11 @@ function generateUniqueString(prefix) {
return prefix + Date.now() + Math.round(Math.random() * 1000);
}

async function createAccount(masterAccount, options = { amount: INITIAL_BALANCE, trials: 5 }) {
await masterAccount.fetchState();
async function createAccount(near, options = { amount: INITIAL_BALANCE }) {
const newAccountName = generateUniqueString('test');
const newPublicKey = await masterAccount.connection.signer.createKey(newAccountName, networkId);
await masterAccount.createAccount(newAccountName, newPublicKey, options.amount);
return new nearApi.Account(masterAccount.connection, newAccountName);
const newPublicKey = await near.connection.signer.createKey(newAccountName, networkId);
await near.createAccount(newAccountName, newPublicKey, options.amount);
return new nearApi.Account(near.connection, newAccountName);
}

async function deployContract(workingAccount, contractId, options = { amount: INITIAL_BALANCE.div(new BN(10)) }) {
Expand Down

0 comments on commit ed354a2

Please sign in to comment.