Skip to content

Commit

Permalink
test: add a secp156k1 send money test
Browse files Browse the repository at this point in the history
  • Loading branch information
gtsonevv committed Jul 4, 2024
1 parent effe3d4 commit fc951f3
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
10 changes: 10 additions & 0 deletions packages/accounts/test/account.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ const { TypedError } = require('@near-js/types');
const fs = require('fs');

const { Account, Contract } = require('../lib');
const { KeyType } = require( '@near-js/crypto' );
const testUtils = require('./test-utils');

let nearjs;
Expand Down Expand Up @@ -49,6 +50,15 @@ test('create account with a secp256k1 key and then view account returns the crea
expect(state.amount).toEqual(newAmount.toString());
});

test('Secp256k1 send money', async() => {
const sender = await testUtils.createAccount(nearjs, KeyType.SECP256K1);
const receiver = await testUtils.createAccount(nearjs, KeyType.SECP256K1);
const { amount: receiverAmount } = await receiver.state();
await sender.sendMoney(receiver.accountId, BigInt(10000));
const state = await receiver.state();
expect(state.amount).toEqual((BigInt(receiverAmount) + BigInt(10000)).toString());
});

test('send money', async() => {
const sender = await testUtils.createAccount(nearjs);
const receiver = await testUtils.createAccount(nearjs);
Expand Down
6 changes: 3 additions & 3 deletions packages/accounts/test/test-utils.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const { KeyPair } = require('@near-js/crypto');
const { KeyPair, KeyType } = require('@near-js/crypto');
const { InMemoryKeyStore } = require('@near-js/keystores');
const fs = require('fs').promises;
const path = require('path');
Expand Down Expand Up @@ -81,9 +81,9 @@ function generateUniqueString(prefix) {
return result + '.test.near';
}

async function createAccount({ accountCreator, connection }) {
async function createAccount({ accountCreator, connection }, keyType = KeyType.ED25519) {
const newAccountName = generateUniqueString('test');
const newPublicKey = await connection.signer.createKey(newAccountName, networkId);
const newPublicKey = await connection.signer.createKey(newAccountName, networkId, keyType);
await accountCreator.createAccount(newAccountName, newPublicKey);
return new Account(connection, newAccountName);
}
Expand Down

0 comments on commit fc951f3

Please sign in to comment.