solana/web3.js/test/budget-program.test.js

81 lines
2.2 KiB
JavaScript
Raw Normal View History

2018-09-18 12:46:59 -07:00
// @flow
import {Account} from '../src/account';
2018-09-20 10:10:46 -07:00
import {BudgetProgram} from '../src/budget-program';
2018-09-18 12:46:59 -07:00
test('pay', () => {
const from = new Account();
2018-09-24 19:17:59 -07:00
const program = new Account();
2018-09-18 12:46:59 -07:00
const to = new Account();
let transaction;
2018-09-20 10:10:46 -07:00
transaction = BudgetProgram.pay(
2018-09-18 12:46:59 -07:00
from.publicKey,
2018-09-24 19:17:59 -07:00
program.publicKey,
2018-09-18 12:46:59 -07:00
to.publicKey,
123,
);
2019-05-24 15:07:16 -07:00
expect(transaction.instructions[0].keys).toHaveLength(2);
expect(transaction.instructions[1].keys).toHaveLength(2);
2018-09-26 09:04:04 -07:00
// TODO: Validate transaction contents more
2018-09-18 12:46:59 -07:00
2018-09-20 10:10:46 -07:00
transaction = BudgetProgram.pay(
2018-09-18 12:46:59 -07:00
from.publicKey,
2018-09-24 19:17:59 -07:00
program.publicKey,
2018-09-18 12:46:59 -07:00
to.publicKey,
123,
2018-09-20 10:10:46 -07:00
BudgetProgram.signatureCondition(from.publicKey),
2018-09-18 12:46:59 -07:00
);
2019-05-24 15:07:16 -07:00
expect(transaction.instructions[0].keys).toHaveLength(2);
expect(transaction.instructions[1].keys).toHaveLength(1);
2018-09-26 09:04:04 -07:00
// TODO: Validate transaction contents more
2018-09-18 12:46:59 -07:00
2018-09-20 10:10:46 -07:00
transaction = BudgetProgram.pay(
2018-09-18 12:46:59 -07:00
from.publicKey,
2018-09-24 19:17:59 -07:00
program.publicKey,
2018-09-18 12:46:59 -07:00
to.publicKey,
123,
2018-09-20 10:10:46 -07:00
BudgetProgram.signatureCondition(from.publicKey),
BudgetProgram.timestampCondition(from.publicKey, new Date()),
2018-09-18 12:46:59 -07:00
);
2019-05-24 15:07:16 -07:00
expect(transaction.instructions[0].keys).toHaveLength(2);
expect(transaction.instructions[1].keys).toHaveLength(1);
2018-09-26 09:04:04 -07:00
// TODO: Validate transaction contents more
2018-09-26 09:49:59 -07:00
transaction = BudgetProgram.payOnBoth(
from.publicKey,
program.publicKey,
to.publicKey,
123,
BudgetProgram.signatureCondition(from.publicKey),
BudgetProgram.timestampCondition(from.publicKey, new Date()),
);
2019-05-24 15:07:16 -07:00
expect(transaction.instructions[0].keys).toHaveLength(2);
expect(transaction.instructions[1].keys).toHaveLength(1);
2018-09-26 09:49:59 -07:00
// TODO: Validate transaction contents more
2018-09-26 09:04:04 -07:00
});
test('apply', () => {
const from = new Account();
const program = new Account();
const to = new Account();
let transaction;
transaction = BudgetProgram.applyTimestamp(
from.publicKey,
program.publicKey,
to.publicKey,
new Date(),
);
expect(transaction.keys).toHaveLength(3);
// TODO: Validate transaction contents more
transaction = BudgetProgram.applySignature(
from.publicKey,
program.publicKey,
to.publicKey,
);
expect(transaction.keys).toHaveLength(3);
// TODO: Validate transaction contents more
2018-09-18 12:46:59 -07:00
});