Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updated tests #24

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,10 @@ Some basic tests can now be run locally to verify the library and your simplewal
To run the tests, clone the repository and then:

npm install
npm test

Run npm test script with params to match your own hostname, port, RPC username (if RPC login enabled,) and RPC password.

npm --port=38083 --host=127.0.0.1 --user=user --password=password run test

## Example Usage

Expand Down
115 changes: 101 additions & 14 deletions test/index_test.js
Original file line number Diff line number Diff line change
@@ -1,27 +1,41 @@
'use strict';
var moneroWallet = require('../lib/wallet');
const moneroWallet = require('../lib/wallet');

// Run npm test script with params to match your own hostname, port, RPC username (if RPC login enabled,) and RPC password.
// npm --port=38082 --host=127.0.0.1 --user=user --password=password run test

const PORT = process.env.npm_config_port || 38082;
const HOST_NAME = process.env.npm_config_host || '127.0.0.1';
const USER = process.env.npm_config_user || '';
const PASSWORD = process.env.npm_config_password || '';

describe('moneroWallet', () => {
const Wallet = new moneroWallet('127.0.0.1', 28082, 'user', 'pass'); // Edit to match your own hostname, port, RPC username (if RPC login enabled,) and RPC password.

// Disabled these checks because users may access unique daemon hostname:port combinations.
// describe('constructor', () => {
// it('should have default host set to `127.0.0.1`', () => {
// new moneroWallet().hostname.should.equal('127.0.0.1');
// });
//
// // it('should have default port set to 18082', () => {
// // new moneroWallet().port.should.equal(18082);
// // });
// });
const Wallet = new moneroWallet(HOST_NAME, PORT, USER, PASSWORD);

describe('constructor', () => {
it('should return appropriate object', () => {
const Wallet = new moneroWallet(HOST_NAME, PORT, USER, PASSWORD);
Wallet.hostname.should.equal(HOST_NAME);
Wallet.port.should.equal(PORT);
Wallet.user.should.equal(USER);
Wallet.pass.should.equal(PASSWORD);
});
// it(`should have default host set to "127.0.0.1"`, () => {
// new moneroWallet().hostname.should.equal('127.0.0.1');
// });
//
// it('should have default port set to 18082', () => {
// new moneroWallet().port.should.equal(18082);
// });
});

describe('methods', () => {
describe('create_wallet()', () => {
it('should create a new wallet monero_wallet (if monero_wallet doesn\'t exist)', (done) => {
Wallet.create_wallet('monero_wallet').then(function(result){
if (result.hasOwnProperty('error')) {
if (result.hasOwnProperty('error')) {
if (result.error.code == -21) {
if (result.error.code === -21) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

result.error.code.should.be.equal(-21)
}
}
Expand Down Expand Up @@ -59,5 +73,78 @@ describe('moneroWallet', () => {
})
})
})

describe('getPayments()', () => {
it('should return empty object, because there was not payments with such pid', (done) => {
Wallet.getPayments('60900e5603bf96e3').then(function(result){
result.should.be.a.Object().and.empty();
done();
});
});
});

describe('getBulkPayments()', () => {
it('should return list of payments', (done) => {
Wallet.getBulkPayments().then(function(result){
result.payments.should.be.a.Array();
done();
});
});
});

describe('incomingTransfers()', () => {
it('should return list of all transfers', (done) => {
Wallet.incomingTransfers('all').then(function(result){
result.transfers.should.be.a.Array();
done();
});
});
});

describe('incomingTransfers()', () => {
it('should return list of available transfers', (done) => {
Wallet.incomingTransfers('available').then(function(result){
result.transfers.should.be.a.Array();
done();
});
});
});

describe('incomingTransfers()', () => {
it('should return list of unavailable transfers', (done) => {
Wallet.incomingTransfers('unavailable').then(function(result){
result.transfers.should.be.a.Array();
done();
});
});
});

describe('queryKey()', () => {
it('should return mnemonic key string', (done) => {
Wallet.queryKey('mnemonic').then(function(result){
result.key.should.be.a.String();
done();
});
});
});

describe('height()', () => {
it('should return blockchain height', (done) => {
Wallet.height().then(function(result){
result.height.should.be.a.Number();
done();
});
});
});


describe('stopWallet()', () => {
it('should return empty object', (done) => {
Wallet.stopWallet().then(function(result){
result.should.be.a.Object().and.empty();
done();
})
})
})
})
})