Remove Budget from CLI (#11451)
* Remove support for Budget Also: * Make "pay" command a deprecated alias for the "transfer" command * chore: remove budget from web3.js * Drop Budget depedency from core Validators no longer ship with builtin Budget
This commit is contained in:
@ -1,67 +0,0 @@
|
||||
/* eslint-disable import/no-commonjs */
|
||||
|
||||
/*
|
||||
Common code for the budget program examples
|
||||
*/
|
||||
|
||||
function getTransactionFee(connection) {
|
||||
return connection.getRecentBlockhash().then(response => {
|
||||
return response.feeCalculator;
|
||||
});
|
||||
}
|
||||
|
||||
function showBalance(connection, account1, account2, contractState) {
|
||||
console.log(`\n== Account State`);
|
||||
return Promise.all([
|
||||
connection.getBalance(account1.publicKey),
|
||||
connection.getBalance(account2.publicKey),
|
||||
connection.getBalance(contractState.publicKey),
|
||||
]).then(([fromBalance, toBalance, contractStateBalance]) => {
|
||||
console.log(
|
||||
`Account1: ${account1.publicKey} has a balance of ${fromBalance}`,
|
||||
);
|
||||
console.log(
|
||||
`Account2: ${account2.publicKey} has a balance of ${toBalance}`,
|
||||
);
|
||||
console.log(
|
||||
`Contract State: ${contractState.publicKey} has a balance of ${contractStateBalance}`,
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
function confirmTransaction(connection, signature) {
|
||||
console.log('Confirming transaction:', signature);
|
||||
return connection.getSignatureStatus(signature).then(confirmation => {
|
||||
if (confirmation && 'Ok' in confirmation) {
|
||||
console.log('Transaction confirmed');
|
||||
} else if (confirmation) {
|
||||
throw new Error(
|
||||
`Transaction was not confirmed (${JSON.stringify(confirmation.Err)})`,
|
||||
);
|
||||
} else {
|
||||
throw new Error(`Transaction was not confirmed (${confirmation})`);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function airDrop(connection, account, feeCalculator) {
|
||||
const airdrop = 100 + 5 * feeCalculator.targetLamportsPerSignature;
|
||||
console.log(`\n== Requesting airdrop of ${airdrop} to ${account.publicKey}`);
|
||||
return connection
|
||||
.requestAirdrop(account.publicKey, airdrop)
|
||||
.then(signature => confirmTransaction(connection, signature));
|
||||
}
|
||||
|
||||
function sleep(millis) {
|
||||
return new Promise(resolve => {
|
||||
setTimeout(resolve, millis);
|
||||
});
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
airDrop,
|
||||
confirmTransaction,
|
||||
getTransactionFee,
|
||||
showBalance,
|
||||
sleep,
|
||||
};
|
@ -1,76 +0,0 @@
|
||||
/* eslint-disable import/no-commonjs */
|
||||
|
||||
/*
|
||||
Example of using the Budget program to perform a time-lock payment of 50
|
||||
lamports from account1 to account2.
|
||||
*/
|
||||
|
||||
const common = require('./budget-common');
|
||||
const solanaWeb3 = require('..');
|
||||
//const solanaWeb3 = require('@solana/web3.js');
|
||||
|
||||
const account1 = new solanaWeb3.Account();
|
||||
const account2 = new solanaWeb3.Account();
|
||||
const contractState = new solanaWeb3.Account();
|
||||
|
||||
let url;
|
||||
url = 'http://localhost:8899';
|
||||
const connection = new solanaWeb3.Connection(url, 'recent');
|
||||
const getTransactionFee = () => common.getTransactionFee(connection);
|
||||
const showBalance = () =>
|
||||
common.showBalance(connection, account1, account2, contractState);
|
||||
const confirmTransaction = signature =>
|
||||
common.confirmTransaction(connection, signature);
|
||||
const airDrop = feeCalculator =>
|
||||
common.airDrop(connection, account1, feeCalculator);
|
||||
|
||||
getTransactionFee().then(feeCalculator => {
|
||||
airDrop(feeCalculator)
|
||||
.then(showBalance)
|
||||
.then(() => {
|
||||
console.log(`\n== Initializing contract`);
|
||||
const transaction = solanaWeb3.BudgetProgram.pay(
|
||||
account1.publicKey,
|
||||
contractState.publicKey,
|
||||
account2.publicKey,
|
||||
50,
|
||||
solanaWeb3.BudgetProgram.timestampCondition(
|
||||
account1.publicKey,
|
||||
new Date('2050'),
|
||||
),
|
||||
);
|
||||
return solanaWeb3.sendAndConfirmTransaction(
|
||||
connection,
|
||||
transaction,
|
||||
account1,
|
||||
contractState,
|
||||
);
|
||||
})
|
||||
.then(confirmTransaction)
|
||||
.then(showBalance)
|
||||
.then(() => {
|
||||
console.log(`\n== Witness contract`);
|
||||
const transaction = solanaWeb3.BudgetProgram.applyTimestamp(
|
||||
account1.publicKey,
|
||||
contractState.publicKey,
|
||||
account2.publicKey,
|
||||
new Date('2050'),
|
||||
);
|
||||
return solanaWeb3.sendAndConfirmTransaction(
|
||||
connection,
|
||||
transaction,
|
||||
account1,
|
||||
contractState,
|
||||
);
|
||||
})
|
||||
.then(confirmTransaction)
|
||||
.then(showBalance)
|
||||
|
||||
.then(() => {
|
||||
console.log('\nDone');
|
||||
})
|
||||
|
||||
.catch(err => {
|
||||
console.log(err);
|
||||
});
|
||||
});
|
@ -1,119 +0,0 @@
|
||||
/* eslint-disable import/no-commonjs */
|
||||
|
||||
/*
|
||||
Example of using the Budget program to perform a payment authorized by two parties
|
||||
*/
|
||||
|
||||
const common = require('./budget-common');
|
||||
const solanaWeb3 = require('..');
|
||||
//const solanaWeb3 = require('@solana/web3.js');
|
||||
|
||||
const account1 = new solanaWeb3.Account();
|
||||
const account2 = new solanaWeb3.Account();
|
||||
const contractState = new solanaWeb3.Account();
|
||||
|
||||
const approver1 = new solanaWeb3.Account();
|
||||
const approver2 = new solanaWeb3.Account();
|
||||
|
||||
let url;
|
||||
url = 'http://localhost:8899';
|
||||
//url = 'http://devnet.solana.com';
|
||||
const connection = new solanaWeb3.Connection(url, 'recent');
|
||||
const getTransactionFee = () => common.getTransactionFee(connection);
|
||||
const showBalance = () =>
|
||||
common.showBalance(connection, account1, account2, contractState);
|
||||
const confirmTransaction = signature =>
|
||||
common.confirmTransaction(connection, signature);
|
||||
const airDrop = feeCalculator =>
|
||||
common.airDrop(connection, account1, feeCalculator);
|
||||
|
||||
getTransactionFee().then(feeCalculator => {
|
||||
airDrop(feeCalculator)
|
||||
.then(() => {
|
||||
console.log(`\n== Move 1 lamport to approver1`);
|
||||
const transaction = solanaWeb3.SystemProgram.transfer(
|
||||
account1.publicKey,
|
||||
approver1.publicKey,
|
||||
1 + feeCalculator.lamportsPerSignature,
|
||||
);
|
||||
return solanaWeb3.sendAndConfirmTransaction(
|
||||
connection,
|
||||
transaction,
|
||||
account1,
|
||||
);
|
||||
})
|
||||
.then(confirmTransaction)
|
||||
.then(getTransactionFee)
|
||||
.then(() => {
|
||||
console.log(`\n== Move 1 lamport to approver2`);
|
||||
const transaction = solanaWeb3.SystemProgram.transfer(
|
||||
account1.publicKey,
|
||||
approver2.publicKey,
|
||||
1 + feeCalculator.lamportsPerSignature,
|
||||
);
|
||||
return solanaWeb3.sendAndConfirmTransaction(
|
||||
connection,
|
||||
transaction,
|
||||
account1,
|
||||
);
|
||||
})
|
||||
.then(confirmTransaction)
|
||||
.then(showBalance)
|
||||
.then(() => {
|
||||
console.log(`\n== Initializing contract`);
|
||||
const transaction = solanaWeb3.BudgetProgram.payOnBoth(
|
||||
account1.publicKey,
|
||||
contractState.publicKey,
|
||||
account2.publicKey,
|
||||
50,
|
||||
solanaWeb3.BudgetProgram.signatureCondition(approver1.publicKey),
|
||||
solanaWeb3.BudgetProgram.signatureCondition(approver2.publicKey),
|
||||
);
|
||||
return solanaWeb3.sendAndConfirmTransaction(
|
||||
connection,
|
||||
transaction,
|
||||
account1,
|
||||
contractState,
|
||||
);
|
||||
})
|
||||
.then(confirmTransaction)
|
||||
.then(showBalance)
|
||||
.then(() => {
|
||||
console.log(`\n== Apply approver 1`);
|
||||
const transaction = solanaWeb3.BudgetProgram.applySignature(
|
||||
approver1.publicKey,
|
||||
contractState.publicKey,
|
||||
account2.publicKey,
|
||||
);
|
||||
return solanaWeb3.sendAndConfirmTransaction(
|
||||
connection,
|
||||
transaction,
|
||||
approver1,
|
||||
);
|
||||
})
|
||||
.then(confirmTransaction)
|
||||
.then(showBalance)
|
||||
.then(() => {
|
||||
console.log(`\n== Apply approver 2`);
|
||||
const transaction = solanaWeb3.BudgetProgram.applySignature(
|
||||
approver2.publicKey,
|
||||
contractState.publicKey,
|
||||
account2.publicKey,
|
||||
);
|
||||
return solanaWeb3.sendAndConfirmTransaction(
|
||||
connection,
|
||||
transaction,
|
||||
approver2,
|
||||
);
|
||||
})
|
||||
.then(confirmTransaction)
|
||||
.then(showBalance)
|
||||
|
||||
.then(() => {
|
||||
console.log('\nDone');
|
||||
})
|
||||
|
||||
.catch(err => {
|
||||
console.log(err);
|
||||
});
|
||||
});
|
4
web3.js/module.d.ts
vendored
4
web3.js/module.d.ts
vendored
@ -32,10 +32,6 @@ declare module '@solana/web3.js' {
|
||||
lamportsPerSignature: number;
|
||||
};
|
||||
|
||||
// === src/budget-program.js ===
|
||||
|
||||
/* TODO */
|
||||
|
||||
// === src/connection.js ===
|
||||
export type Context = {
|
||||
slot: number;
|
||||
|
@ -54,9 +54,6 @@ declare module '@solana/web3.js' {
|
||||
lamportsPerSignature: number,
|
||||
};
|
||||
|
||||
// === src/budget-program.js ===
|
||||
/* TODO */
|
||||
|
||||
// === src/connection.js ===
|
||||
declare export type Context = {
|
||||
slot: number,
|
||||
|
@ -1,390 +0,0 @@
|
||||
// @flow
|
||||
|
||||
import * as BufferLayout from 'buffer-layout';
|
||||
|
||||
import {Transaction} from './transaction';
|
||||
import {PublicKey} from './publickey';
|
||||
import {SystemProgram} from './system-program';
|
||||
|
||||
/**
|
||||
* Represents a condition that is met by executing a `applySignature()`
|
||||
* transaction
|
||||
*
|
||||
* @typedef {Object} SignatureCondition
|
||||
* @property {string} type Must equal the string 'timestamp'
|
||||
* @property {PublicKey} from Public key from which `applySignature()` will be accepted from
|
||||
*/
|
||||
export type SignatureCondition = {
|
||||
type: 'signature',
|
||||
from: PublicKey,
|
||||
};
|
||||
|
||||
/**
|
||||
* Represents a condition that is met by executing a `applyTimestamp()`
|
||||
* transaction
|
||||
*
|
||||
* @typedef {Object} TimestampCondition
|
||||
* @property {string} type Must equal the string 'timestamp'
|
||||
* @property {PublicKey} from Public key from which `applyTimestamp()` will be accepted from
|
||||
* @property {Date} when The timestamp that was observed
|
||||
*/
|
||||
export type TimestampCondition = {
|
||||
type: 'timestamp',
|
||||
from: PublicKey,
|
||||
when: Date,
|
||||
};
|
||||
|
||||
/**
|
||||
* Represents a payment to a given public key
|
||||
*
|
||||
* @typedef {Object} Payment
|
||||
* @property {number} amount Number of lamports
|
||||
* @property {PublicKey} to Public key of the recipient
|
||||
*/
|
||||
export type Payment = {
|
||||
amount: number,
|
||||
to: PublicKey,
|
||||
};
|
||||
|
||||
/**
|
||||
* A condition that can unlock a payment
|
||||
*
|
||||
* @typedef {SignatureCondition|TimestampCondition} BudgetCondition
|
||||
*/
|
||||
export type BudgetCondition = SignatureCondition | TimestampCondition;
|
||||
|
||||
/**
|
||||
* @private
|
||||
*/
|
||||
function serializePayment(payment: Payment): Buffer {
|
||||
const toData = payment.to.toBuffer();
|
||||
const data = Buffer.alloc(8 + toData.length);
|
||||
data.writeUInt32LE(payment.amount, 0);
|
||||
toData.copy(data, 8);
|
||||
return data;
|
||||
}
|
||||
|
||||
/**
|
||||
* @private
|
||||
*/
|
||||
function serializeDate(when: Date): Buffer {
|
||||
const data = Buffer.alloc(8 + 20);
|
||||
data.writeUInt32LE(20, 0); // size of timestamp as u64
|
||||
|
||||
function iso(date) {
|
||||
function pad(number) {
|
||||
if (number < 10) {
|
||||
return '0' + number;
|
||||
}
|
||||
return number;
|
||||
}
|
||||
|
||||
return (
|
||||
date.getUTCFullYear() +
|
||||
'-' +
|
||||
pad(date.getUTCMonth() + 1) +
|
||||
'-' +
|
||||
pad(date.getUTCDate()) +
|
||||
'T' +
|
||||
pad(date.getUTCHours()) +
|
||||
':' +
|
||||
pad(date.getUTCMinutes()) +
|
||||
':' +
|
||||
pad(date.getUTCSeconds()) +
|
||||
'Z'
|
||||
);
|
||||
}
|
||||
data.write(iso(when), 8);
|
||||
return data;
|
||||
}
|
||||
|
||||
/**
|
||||
* @private
|
||||
*/
|
||||
function serializeCondition(condition: BudgetCondition) {
|
||||
switch (condition.type) {
|
||||
case 'timestamp': {
|
||||
const date = serializeDate(condition.when);
|
||||
const from = condition.from.toBuffer();
|
||||
|
||||
const data = Buffer.alloc(4 + date.length + from.length);
|
||||
data.writeUInt32LE(0, 0); // Condition enum = Timestamp
|
||||
date.copy(data, 4);
|
||||
from.copy(data, 4 + date.length);
|
||||
return data;
|
||||
}
|
||||
case 'signature': {
|
||||
const from = condition.from.toBuffer();
|
||||
const data = Buffer.alloc(4 + from.length);
|
||||
data.writeUInt32LE(1, 0); // Condition enum = Signature
|
||||
from.copy(data, 4);
|
||||
return data;
|
||||
}
|
||||
default:
|
||||
throw new Error(`Unknown condition type: ${condition.type}`);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Factory class for transactions to interact with the Budget program
|
||||
*/
|
||||
export class BudgetProgram {
|
||||
/**
|
||||
* Public key that identifies the Budget program
|
||||
*/
|
||||
static get programId(): PublicKey {
|
||||
return new PublicKey('Budget1111111111111111111111111111111111111');
|
||||
}
|
||||
|
||||
/**
|
||||
* The amount of space this program requires
|
||||
*/
|
||||
static get space(): number {
|
||||
return 128;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a timestamp condition
|
||||
*/
|
||||
static timestampCondition(from: PublicKey, when: Date): TimestampCondition {
|
||||
return {
|
||||
type: 'timestamp',
|
||||
from,
|
||||
when,
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a signature condition
|
||||
*/
|
||||
static signatureCondition(from: PublicKey): SignatureCondition {
|
||||
return {
|
||||
type: 'signature',
|
||||
from,
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates a transaction that transfers lamports once any of the conditions are met
|
||||
*/
|
||||
static pay(
|
||||
from: PublicKey,
|
||||
program: PublicKey,
|
||||
to: PublicKey,
|
||||
amount: number,
|
||||
...conditions: Array<BudgetCondition>
|
||||
): Transaction {
|
||||
const data = Buffer.alloc(1024);
|
||||
let pos = 0;
|
||||
data.writeUInt32LE(0, pos); // NewBudget instruction
|
||||
pos += 4;
|
||||
|
||||
switch (conditions.length) {
|
||||
case 0: {
|
||||
data.writeUInt32LE(0, pos); // BudgetExpr enum = Pay
|
||||
pos += 4;
|
||||
|
||||
{
|
||||
const payment = serializePayment({amount, to});
|
||||
payment.copy(data, pos);
|
||||
pos += payment.length;
|
||||
}
|
||||
const trimmedData = data.slice(0, pos);
|
||||
|
||||
const transaction = SystemProgram.createAccount({
|
||||
fromPubkey: from,
|
||||
newAccountPubkey: program,
|
||||
lamports: amount,
|
||||
space: trimmedData.length,
|
||||
programId: this.programId,
|
||||
});
|
||||
|
||||
return transaction.add({
|
||||
keys: [
|
||||
{pubkey: to, isSigner: false, isWritable: true},
|
||||
{pubkey: program, isSigner: false, isWritable: true},
|
||||
],
|
||||
programId: this.programId,
|
||||
data: trimmedData,
|
||||
});
|
||||
}
|
||||
case 1: {
|
||||
data.writeUInt32LE(1, pos); // BudgetExpr enum = After
|
||||
pos += 4;
|
||||
{
|
||||
const condition = conditions[0];
|
||||
|
||||
const conditionData = serializeCondition(condition);
|
||||
conditionData.copy(data, pos);
|
||||
pos += conditionData.length;
|
||||
|
||||
data.writeUInt32LE(0, pos); // BudgetExpr enum = Pay
|
||||
pos += 4;
|
||||
|
||||
const paymentData = serializePayment({amount, to});
|
||||
paymentData.copy(data, pos);
|
||||
pos += paymentData.length;
|
||||
}
|
||||
const trimmedData = data.slice(0, pos);
|
||||
|
||||
const transaction = SystemProgram.createAccount({
|
||||
fromPubkey: from,
|
||||
newAccountPubkey: program,
|
||||
lamports: amount,
|
||||
space: trimmedData.length,
|
||||
programId: this.programId,
|
||||
});
|
||||
|
||||
return transaction.add({
|
||||
keys: [{pubkey: program, isSigner: false, isWritable: true}],
|
||||
programId: this.programId,
|
||||
data: trimmedData,
|
||||
});
|
||||
}
|
||||
|
||||
case 2: {
|
||||
data.writeUInt32LE(2, pos); // BudgetExpr enum = Or
|
||||
pos += 4;
|
||||
|
||||
for (let condition of conditions) {
|
||||
const conditionData = serializeCondition(condition);
|
||||
conditionData.copy(data, pos);
|
||||
pos += conditionData.length;
|
||||
|
||||
data.writeUInt32LE(0, pos); // BudgetExpr enum = Pay
|
||||
pos += 4;
|
||||
|
||||
const paymentData = serializePayment({amount, to});
|
||||
paymentData.copy(data, pos);
|
||||
pos += paymentData.length;
|
||||
}
|
||||
const trimmedData = data.slice(0, pos);
|
||||
|
||||
const transaction = SystemProgram.createAccount({
|
||||
fromPubkey: from,
|
||||
newAccountPubkey: program,
|
||||
lamports: amount,
|
||||
space: trimmedData.length,
|
||||
programId: this.programId,
|
||||
});
|
||||
|
||||
return transaction.add({
|
||||
keys: [{pubkey: program, isSigner: false, isWritable: true}],
|
||||
programId: this.programId,
|
||||
data: trimmedData,
|
||||
});
|
||||
}
|
||||
|
||||
default:
|
||||
throw new Error(
|
||||
`A maximum of two conditions are supported: ${conditions.length} provided`,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates a transaction that transfers lamports once both conditions are met
|
||||
*/
|
||||
static payOnBoth(
|
||||
from: PublicKey,
|
||||
program: PublicKey,
|
||||
to: PublicKey,
|
||||
amount: number,
|
||||
condition1: BudgetCondition,
|
||||
condition2: BudgetCondition,
|
||||
): Transaction {
|
||||
const data = Buffer.alloc(1024);
|
||||
let pos = 0;
|
||||
data.writeUInt32LE(0, pos); // NewBudget instruction
|
||||
pos += 4;
|
||||
|
||||
data.writeUInt32LE(3, pos); // BudgetExpr enum = And
|
||||
pos += 4;
|
||||
|
||||
for (let condition of [condition1, condition2]) {
|
||||
const conditionData = serializeCondition(condition);
|
||||
conditionData.copy(data, pos);
|
||||
pos += conditionData.length;
|
||||
}
|
||||
|
||||
data.writeUInt32LE(0, pos); // BudgetExpr enum = Pay
|
||||
pos += 4;
|
||||
|
||||
const paymentData = serializePayment({amount, to});
|
||||
paymentData.copy(data, pos);
|
||||
pos += paymentData.length;
|
||||
|
||||
const trimmedData = data.slice(0, pos);
|
||||
|
||||
const transaction = SystemProgram.createAccount({
|
||||
fromPubkey: from,
|
||||
newAccountPubkey: program,
|
||||
lamports: amount,
|
||||
space: trimmedData.length,
|
||||
programId: this.programId,
|
||||
});
|
||||
|
||||
return transaction.add({
|
||||
keys: [{pubkey: program, isSigner: false, isWritable: true}],
|
||||
programId: this.programId,
|
||||
data: trimmedData,
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates a transaction that applies a timestamp, which could enable a
|
||||
* pending payment to proceed.
|
||||
*/
|
||||
static applyTimestamp(
|
||||
from: PublicKey,
|
||||
program: PublicKey,
|
||||
to: PublicKey,
|
||||
when: Date,
|
||||
): Transaction {
|
||||
const whenData = serializeDate(when);
|
||||
const data = Buffer.alloc(4 + whenData.length);
|
||||
|
||||
data.writeUInt32LE(1, 0); // ApplyTimestamp instruction
|
||||
whenData.copy(data, 4);
|
||||
|
||||
return new Transaction().add({
|
||||
keys: [
|
||||
{pubkey: from, isSigner: true, isWritable: true},
|
||||
{pubkey: program, isSigner: false, isWritable: true},
|
||||
{pubkey: to, isSigner: false, isWritable: true},
|
||||
],
|
||||
programId: this.programId,
|
||||
data,
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates a transaction that applies a signature, which could enable a
|
||||
* pending payment to proceed.
|
||||
*/
|
||||
static applySignature(
|
||||
from: PublicKey,
|
||||
program: PublicKey,
|
||||
to: PublicKey,
|
||||
): Transaction {
|
||||
const dataLayout = BufferLayout.struct([BufferLayout.u32('instruction')]);
|
||||
|
||||
const data = Buffer.alloc(dataLayout.span);
|
||||
dataLayout.encode(
|
||||
{
|
||||
instruction: 2, // ApplySignature instruction
|
||||
},
|
||||
data,
|
||||
);
|
||||
|
||||
return new Transaction().add({
|
||||
keys: [
|
||||
{pubkey: from, isSigner: true, isWritable: true},
|
||||
{pubkey: program, isSigner: false, isWritable: true},
|
||||
{pubkey: to, isSigner: false, isWritable: true},
|
||||
],
|
||||
programId: this.programId,
|
||||
data,
|
||||
});
|
||||
}
|
||||
}
|
@ -1,7 +1,6 @@
|
||||
// @flow
|
||||
export {Account} from './account';
|
||||
export {BpfLoader} from './bpf-loader';
|
||||
export {BudgetProgram} from './budget-program';
|
||||
export {Connection} from './connection';
|
||||
export {Loader} from './loader';
|
||||
export {Message} from './message';
|
||||
|
@ -1,80 +0,0 @@
|
||||
// @flow
|
||||
|
||||
import {Account} from '../src/account';
|
||||
import {BudgetProgram} from '../src/budget-program';
|
||||
|
||||
test('pay', () => {
|
||||
const from = new Account();
|
||||
const program = new Account();
|
||||
const to = new Account();
|
||||
let transaction;
|
||||
|
||||
transaction = BudgetProgram.pay(
|
||||
from.publicKey,
|
||||
program.publicKey,
|
||||
to.publicKey,
|
||||
123,
|
||||
);
|
||||
expect(transaction.instructions[0].keys).toHaveLength(2);
|
||||
expect(transaction.instructions[1].keys).toHaveLength(2);
|
||||
// TODO: Validate transaction contents more
|
||||
|
||||
transaction = BudgetProgram.pay(
|
||||
from.publicKey,
|
||||
program.publicKey,
|
||||
to.publicKey,
|
||||
123,
|
||||
BudgetProgram.signatureCondition(from.publicKey),
|
||||
);
|
||||
expect(transaction.instructions[0].keys).toHaveLength(2);
|
||||
expect(transaction.instructions[1].keys).toHaveLength(1);
|
||||
// TODO: Validate transaction contents more
|
||||
|
||||
transaction = BudgetProgram.pay(
|
||||
from.publicKey,
|
||||
program.publicKey,
|
||||
to.publicKey,
|
||||
123,
|
||||
BudgetProgram.signatureCondition(from.publicKey),
|
||||
BudgetProgram.timestampCondition(from.publicKey, new Date()),
|
||||
);
|
||||
expect(transaction.instructions[0].keys).toHaveLength(2);
|
||||
expect(transaction.instructions[1].keys).toHaveLength(1);
|
||||
// TODO: Validate transaction contents more
|
||||
|
||||
transaction = BudgetProgram.payOnBoth(
|
||||
from.publicKey,
|
||||
program.publicKey,
|
||||
to.publicKey,
|
||||
123,
|
||||
BudgetProgram.signatureCondition(from.publicKey),
|
||||
BudgetProgram.timestampCondition(from.publicKey, new Date()),
|
||||
);
|
||||
expect(transaction.instructions[0].keys).toHaveLength(2);
|
||||
expect(transaction.instructions[1].keys).toHaveLength(1);
|
||||
// TODO: Validate transaction contents more
|
||||
});
|
||||
|
||||
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
|
||||
});
|
@ -2,8 +2,8 @@
|
||||
|
||||
import {
|
||||
Account,
|
||||
BudgetProgram,
|
||||
Connection,
|
||||
StakeProgram,
|
||||
SystemInstruction,
|
||||
SystemProgram,
|
||||
Transaction,
|
||||
@ -26,8 +26,8 @@ test('createAccount', () => {
|
||||
fromPubkey: new Account().publicKey,
|
||||
newAccountPubkey: new Account().publicKey,
|
||||
lamports: 123,
|
||||
space: BudgetProgram.space,
|
||||
programId: BudgetProgram.programId,
|
||||
space: 0,
|
||||
programId: SystemProgram.programId,
|
||||
};
|
||||
const transaction = SystemProgram.createAccount(params);
|
||||
expect(transaction.instructions).toHaveLength(1);
|
||||
@ -110,8 +110,8 @@ test('createAccountWithSeed', () => {
|
||||
basePubkey: fromPubkey,
|
||||
seed: 'hi there',
|
||||
lamports: 123,
|
||||
space: BudgetProgram.space,
|
||||
programId: BudgetProgram.programId,
|
||||
space: 0,
|
||||
programId: SystemProgram.programId,
|
||||
};
|
||||
const transaction = SystemProgram.createAccountWithSeed(params);
|
||||
expect(transaction.instructions).toHaveLength(1);
|
||||
@ -228,7 +228,6 @@ test('nonceAuthorize', () => {
|
||||
|
||||
test('non-SystemInstruction error', () => {
|
||||
const from = new Account();
|
||||
const program = new Account();
|
||||
const to = new Account();
|
||||
|
||||
const badProgramId = {
|
||||
@ -236,7 +235,7 @@ test('non-SystemInstruction error', () => {
|
||||
{pubkey: from.publicKey, isSigner: true, isWritable: true},
|
||||
{pubkey: to.publicKey, isSigner: false, isWritable: true},
|
||||
],
|
||||
programId: BudgetProgram.programId,
|
||||
programId: StakeProgram.programId,
|
||||
data: Buffer.from([2, 0, 0, 0]),
|
||||
};
|
||||
expect(() => {
|
||||
@ -245,16 +244,10 @@ test('non-SystemInstruction error', () => {
|
||||
);
|
||||
}).toThrow();
|
||||
|
||||
const amount = 123;
|
||||
const recentBlockhash = 'EETubP5AKHgjPAhzPAFcb8BAY1hMH639CWCFTqi3hq1k'; // Arbitrary known recentBlockhash
|
||||
const budgetPay = BudgetProgram.pay(
|
||||
from.publicKey,
|
||||
program.publicKey,
|
||||
to.publicKey,
|
||||
amount,
|
||||
);
|
||||
const transaction = new Transaction({recentBlockhash}).add(budgetPay);
|
||||
transaction.sign(from);
|
||||
const stakePubkey = new Account().publicKey;
|
||||
const authorizedPubkey = new Account().publicKey;
|
||||
const params = {stakePubkey, authorizedPubkey};
|
||||
const transaction = StakeProgram.deactivate(params);
|
||||
|
||||
expect(() => {
|
||||
SystemInstruction.decodeInstructionType(transaction.instructions[1]);
|
||||
|
Reference in New Issue
Block a user