How to use lisk-elements - 10 common examples

To help you get started, we’ve selected a few lisk-elements examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github LiskHQ / lisk-sdk / test / integration / rounds.js View on Github external
localCommon.getNextForger(library, null, (err, delegatePublicKey) => {
					lastBlock = library.modules.blocks.lastBlock.get();
					lastBlockForger = delegatePublicKey;
					tmpAccount = randomUtil.account();

					// Create transfer transaction (fund new account)
					let transaction = elements.transaction.transfer({
						recipientId: tmpAccount.address,
						amount: 5000000000,
						passphrase: accountsFixtures.genesis.passphrase,
					});
					transactions.transfer.push(transaction);

					// Create register delegate transaction
					transaction = elements.transaction.registerDelegate({
						passphrase: tmpAccount.passphrase,
						username: 'my_little_delegate',
					});
					transactions.delegate.push(transaction);

					transaction = elements.transaction.castVotes({
						passphrase: accountsFixtures.genesis.passphrase,
						unvotes: [lastBlockForger],
						votes: [tmpAccount.publicKey],
					});
					transactions.vote.push(transaction);

					const transactionPool = library.rewiredModules.transactions.__get__(
						'__private.transactionPool'
					);
					// Delete two blocks more
github LiskHQ / lisk-sdk / test / integration / transactions / 2.delegates / 2.same.account.different.usernames.js View on Github external
* Copyright © 2018 Lisk Foundation
 *
 * See the LICENSE file at the top-level directory of this distribution
 * for licensing information.
 *
 * Unless otherwise agreed in a custom licensing agreement with the Lisk Foundation,
 * no part of this software, including this file, may be copied, modified,
 * propagated, or distributed except according to the terms contained in the
 * LICENSE file.
 *
 * Removal or modification of this copyright notice is prohibited.
 */

'use strict';

var lisk = require('lisk-elements').default;
var accountFixtures = require('../../../fixtures/accounts');
var randomUtil = require('../../../common/utils/random');
var localCommon = require('../../common');

const { NORMALIZER } = global.constants;

describe('system test (type 2) - double delegate registrations', () => {
	var library;
	localCommon.beforeBlock('system_2_2_delegates_2', lib => {
		library = lib;
	});

	var i = 0;
	var t = 0;

	/* eslint-disable no-loop-func */
github LiskHQ / lisk-sdk / test / common / utils / random.js View on Github external
*
 * See the LICENSE file at the top-level directory of this distribution
 * for licensing information.
 *
 * Unless otherwise agreed in a custom licensing agreement with the Lisk Foundation,
 * no part of this software, including this file, may be copied, modified,
 * propagated, or distributed except according to the terms contained in the
 * LICENSE file.
 *
 * Removal or modification of this copyright notice is prohibited.
 */

'use strict';

var randomstring = require('randomstring');
var lisk = require('lisk-elements').default;
var Bignum = require('../../../helpers/bignum.js');
var accountFixtures = require('../../fixtures/accounts');

var random = {};

// Returns a random number between min (inclusive) and max (exclusive)
random.number = function(min, max) {
	min = Math.ceil(min);
	max = Math.floor(max);
	return Math.floor(Math.random() * (max - min)) + min;
};

// Returns a random username of 16 characters
random.username = function() {
	var randomLetter = randomstring.generate({
		length: 1,
github LiskHQ / lisk-sdk / test / functional / http / post / 0.transfer.js View on Github external
it('with lowercase recipientId should fail', () => {
			transaction = randomUtil.transaction();
			transaction.recipientId = transaction.recipientId.toLowerCase();
			transaction.signature = crypto.randomBytes(64).toString('hex');
			transaction.id = lisk.transaction.utils.getTransactionId(transaction);

			return sendTransactionPromise(transaction, 400).then(res => {
				expect(res.body.message).to.be.equal('Validation errors');
				badTransactions.push(transaction);
			});
		});
	});
github LiskHQ / lisk-sdk-examples / test / unit / logic / multisignature.js View on Github external
it('should return error when value is greater than maximum acceptable value', () => {
				const minimum = MULTISIG_CONSTRAINTS.MIN.MAXIMUM + 1;
				const keysgroup = [
					multiSigAccount1.publicKey,
					multiSigAccount2.publicKey,
				];
				const multisigRegistration6 = lisk.transaction.registerMultisignature({
					passphrase: accountFixtures.genesis.passphrase,
					keysgroup,
					lifetime: 1,
					minimum,
				});

				return expect(() => {
					multisignature.objectNormalize(multisigRegistration6);
				}).to.throw(
					'Failed to validate multisignature schema: Value 16 is greater than maximum 15'
				);
			});
github LiskHQ / lisk-sdk / test / functional / http / post / 4.multisignature.advanced.js View on Github external
it('requesting multisig group transaction from non author account', () => {
				var scenario = scenarios.requesterPublicKey;

				var transaction = lisk.transaction.transfer({
					amount: 1 * NORMALIZER,
					passphrase: scenario.members[0].passphrase,
					recipientId: randomUtil.account().address,
				});
				transaction.requesterPublicKey = scenario.account.publicKey;
				transaction.id = lisk.transaction.utils.getTransactionId(transaction);

				return sendTransactionPromise(
					transaction,
					errorCodes.PROCESSING_ERROR
				).then(res => {
					expect(res.body.message).to.equal('Multisig request is not allowed');
					badTransactions.push(transaction);
				});
			});
		});
github LiskHQ / lisk-sdk / test / integration / transactions / 1.second_signature / 1.1.second_signature.js View on Github external
it('adding to pool second signature registration should be ok', done => {
		transaction1 = lisk.transaction.registerSecondPassphrase({
			passphrase: account.passphrase,
			secondPassphrase: account.secondPassphrase,
			timeOffset: -10000,
		});
		localCommon.addTransaction(library, transaction1, (err, res) => {
			expect(res).to.equal(transaction1.id);
			done();
		});
	});
github LiskHQ / lisk-sdk-examples / test / unit / modules / delegates.js View on Github external
* Copyright © 2018 Lisk Foundation
 *
 * See the LICENSE file at the top-level directory of this distribution
 * for licensing information.
 *
 * Unless otherwise agreed in a custom licensing agreement with the Lisk Foundation,
 * no part of this software, including this file, may be copied, modified,
 * propagated, or distributed except according to the terms contained in the
 * LICENSE file.
 *
 * Removal or modification of this copyright notice is prohibited.
 */

'use strict';

const lisk = require('lisk-elements').cryptography;
const genesisDelegates = require('../../data/genesis_delegates.json');
const delegatesRoundsList = require('../../data/delegates_rounds_list.json');
const accountFixtures = require('../../fixtures/accounts');
const application = require('../../common/application');
const seeder = require('../../common/storage_seed');

let storage;

const exceptions = global.exceptions;
const { ACTIVE_DELEGATES } = global.constants;

describe('delegates', () => {
	let library;

	before(done => {
		application.init(
github LiskHQ / lisk-sdk / test / integration / transactions / 0.0.address_collision.js View on Github external
it('both passphrases should have the same address', done => {
		expect(lisk.cryptography.getAddressFromPublicKey(publicKeys[0])).to.equal(
			lisk.cryptography.getAddressFromPublicKey(publicKeys[1])
		);
		done();
	});
github LiskHQ / lisk-sdk / test / functional / http / post / 7.dapps.out_transfer.js View on Github external
it('without should fail', () => {
				transaction = lisk.transfer.createOutTransfer(
					randomUtil.guestbookDapp.id,
					randomUtil.transaction().id,
					accountFixtures.genesis.address,
					Date.now(),
					account.passphrase
				);
				delete transaction.asset.outTransfer.dappId;

				return sendTransactionPromise(
					transaction,
					errorCodes.PROCESSING_ERROR
				).then(res => {
					expect(res.body.message).to.be.equal(
						'Invalid transaction body - Failed to validate outTransfer schema: Missing required property: dappId'
					);
					badTransactions.push(transaction);