Skip to content
Snippets Groups Projects
Commit f1adf814 authored by Roger Jungemann's avatar Roger Jungemann
Browse files

Allow for transaction against a currently-empty chain

parent 68382816
No related branches found
No related tags found
No related merge requests found
......@@ -55,7 +55,7 @@ steemBroadcast._prepareTransaction = function steemBroadcast$_prepareTransaction
const chainDate = new Date(properties.time + 'Z');
const refBlockNum = (properties.last_irreversible_block_num - 1) & 0xFFFF;
return steemApi.getBlockAsync(properties.last_irreversible_block_num).then((block) => {
const headBlockId = block.previous;
const headBlockId = block ? block.previous : '0000000000000000000000000000000000000000';
return Object.assign({
ref_block_num: refBlockNum,
ref_block_prefix: new Buffer(headBlockId, 'hex').readUInt32LE(4),
......
......@@ -51,6 +51,67 @@ describe('steem.broadcast:', () => {
});
});
describe('no blocks on chain', () => {
it('works', async () => {
const newAccountName = username + '-' + Math.floor(Math.random() * 10000);
const keys = steem.auth.generateKeys(
username, password, ['posting', 'active', 'owner', 'memo']);
const oldGetDynamicGlobalProperties = steem.api.getDynamicGlobalPropertiesAsync;
steem.api.getDynamicGlobalPropertiesAsync = () => Promise.resolve({
time: '2019-04-14T21:30:56',
last_irreversible_block_num: 32047459,
});
// If the block returned is `null`, then no blocks are on the chain yet.
const oldGetBlockAsync = steem.api.getBlockAsync;
steem.api.getBlockAsync = () => Promise.resolve(null);
try {
const tx = await steem.broadcast._prepareTransaction({
extensions: [],
operations: [[
'account_create',
{
fee: '0.000 TESTS',
creator: username,
new_account_name: newAccountName,
owner: {
weight_threshold: 1,
account_auths: [],
key_auths: [[keys.owner, 1]],
},
active: {
weight_threshold: 1,
account_auths: [],
key_auths: [[keys.active, 1]],
},
posting: {
weight_threshold: 1,
account_auths: [],
key_auths: [[keys.posting, 1]],
},
memo_key: keys.memo,
json_metadata: '',
extensions: [],
}
]],
});
tx.should.have.properties([
'expiration',
'ref_block_num',
'ref_block_prefix',
'extensions',
'operations',
]);
} finally {
steem.api.getDynamicGlobalPropertiesAsync = oldGetDynamicGlobalProperties;
steem.api.getBlockAsync = oldGetBlockAsync;
}
});
});
describe('downvoting', () => {
it('works', async () => {
const tx = await steem.broadcast.voteAsync(
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment