Created
August 7, 2019 21:09
-
-
Save drov0/efb8f0a134851030ac2b434520ba333b to your computer and use it in GitHub Desktop.
Hard fork 21 testing by @howo for the witness @steempress
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var steem = require('steem'); | |
steem.api.setOptions({url: 'https://testnet.steemitdev.com/', useAppbaseApi : true, address_prefix : 'TST', 'chain_id' : "46d82ab7d8db682eb1959aed0ada039a6d49afa1602491f93dde9cac3e8e6c32"}); | |
steem.config.set('address_prefix', 'TST') | |
steem.config.set('chain_id', '46d82ab7d8db682eb1959aed0ada039a6d49afa1602491f93dde9cac3e8e6c32') | |
const assert = require("assert") | |
var username = "howo-testnet"; | |
var password = "modepassesecret"; | |
function broadcast(tx, wif) | |
{ | |
return new Promise(resolve => { | |
steem.broadcast.send(tx, {wif}, async function (result, err) { | |
if (!err) { | |
return resolve({error : false, result}) | |
} else { | |
return resolve({error : true , err}) | |
} | |
}); | |
}); | |
} | |
function create_proposal_tx(op_data) | |
{ | |
return new Promise(async resolve => { | |
const wif = steem.auth.toWif(username, password, 'active'); | |
let ops = []; | |
ops.push(['create_proposal', op_data]); | |
let tx = {operations: ops, extensions: []}; | |
return resolve({tx, wif}) | |
}); | |
} | |
function test() | |
{ | |
describe('accountupdate and accountupdate2', () => { | |
it('accountupdate', async () => { | |
const wif = steem.auth.toWif(username, password, 'active'); | |
let ops = []; | |
let account = await steem.api.callAsync('condenser_api.get_accounts', [[username]]); | |
account = account[0]; | |
ops.push([ 'account_update', { | |
'account': username, | |
memo_key : account.memo_key, | |
posting_key : account.posting.key_auths[0][0], | |
active_key : account.active.key_auths[0][0], | |
owner_key : account.owner.key_auths[0][0], | |
'json_metadata': "", | |
"posting_json_metadata" : "" | |
}]); | |
let tx = {operations: ops, extensions: []}; | |
const result = await broadcast(tx, wif); | |
assert(result.error); | |
}); | |
// Fails for some reason with the same params above | |
it('accountupdate2', async () => { | |
const wif = steem.auth.toWif(username, password, 'posting'); | |
let ops = []; | |
let account = await steem.api.callAsync('condenser_api.get_accounts', [[username]]); | |
account = account[0]; | |
ops.push([ 'account_update2', { | |
'account': username, | |
memo_key : account.memo_key, | |
'json_metadata': "", | |
"posting_json_metadata" : "" | |
}]); | |
let tx = {operations: ops, extensions: []}; | |
const result = await broadcast(tx, wif); | |
assert(result.error); | |
}); | |
}); | |
describe('create_proposal', () => { | |
it('create_proposal normal', async () => { | |
let op_data = { | |
'creator': username, | |
'receiver': username, | |
'start_date': '2019-06-01T00:00:00', | |
'end_date': '2019-10-01T00:00:00', | |
'daily_pay': '5486498.000 TBD', | |
'subject': 'Another outstanding proposal', | |
'permlink': "my-super-proposal" | |
}; | |
let data = await create_proposal_tx(op_data); | |
const result = await broadcast(data.tx, data.wif); | |
assert(result.error); | |
}); | |
it('create_proposal ends before today', async () => { | |
let op_data = { | |
'creator': username, | |
'receiver': username, | |
'start_date': '2018-09-01T00:00:00', | |
'end_date': '2018-10-01T00:00:00', | |
'daily_pay': '1.000 TBD', | |
'subject': 'testing', | |
'permlink': "my-super-proposal" | |
}; | |
let data = await create_proposal_tx(op_data); | |
const result = await broadcast(data.tx, data.wif); | |
assert(result.error === false); | |
}); | |
it('create_proposal negative pay', async () => { | |
let op_data = { | |
'creator': username, | |
'receiver': username, | |
'start_date': '2019-09-01T00:00:00', | |
'end_date': '2019-10-01T00:00:00', | |
'daily_pay': '-1.000 TBD', | |
'subject': 'testing', | |
'permlink': "my-super-proposal" | |
}; | |
let data = await create_proposal_tx(op_data); | |
const result = await broadcast(data.tx, data.wif); | |
assert(result.error === false); | |
}); | |
it('Proposal permlink doesnt exists', async () => { | |
let op_data = { | |
'creator': username, | |
'receiver': username, | |
'start_date': '2018-09-01T00:00:00', | |
'end_date': '2018-10-01T00:00:00', | |
'daily_pay': '1.000 TBD', | |
'subject': 'testing', | |
'permlink': "a" | |
}; | |
let data = await create_proposal_tx(op_data); | |
const result = await broadcast(data.tx, data.wif); | |
assert(result.error === false); | |
}); | |
it('Proposal daily pay overly large number', async () => { | |
let op_data = { | |
'creator': username, | |
'receiver': username, | |
'start_date': '2018-09-01T00:00:00', | |
'end_date': '2018-10-01T00:00:00', | |
'daily_pay': '111111111111111111111111111111111.000 TBD', | |
'subject': 'testing', | |
'permlink': "my-super-proposal" | |
}; | |
let data = await create_proposal_tx(op_data); | |
const result = await broadcast(data.tx, data.wif); | |
assert(result.error === false); | |
}); | |
it('Proposal daily pay overly large title', async () => { | |
let op_data = { | |
'creator': username, | |
'receiver': username, | |
'start_date': '2018-09-01T00:00:00', | |
'end_date': '2018-10-01T00:00:00', | |
'daily_pay': '1.000 TBD', | |
'subject': 'tesngtestingtestingtestingtestingtestingtestingtestingtestingtestingtestingtestingtestingtestingtestingtestingtestingtestingtestingtestingtestingtestingtegtestingtestingtestingtestingtestingtestingtestingtestingtestingtestingtestingtestingtestingtestingtestingtestingtestingtestingtestingtestingtestingtestingtestingtestingtesting', | |
'permlink': "my-super-proposal" | |
}; | |
let data = await create_proposal_tx(op_data); | |
const result = await broadcast(data.tx, data.wif); | |
assert(result.error === false); | |
}); | |
it('Proposal start date does not exists', async () => { | |
let op_data = { | |
'creator': username, | |
'receiver': username, | |
'start_date': '-2018-09-01T00:00:00', | |
'end_date': '2018-10-01T00:00:00', | |
'daily_pay': '1.000 TBD', | |
'subject': 'testing', | |
'permlink': "my-super-proposal" | |
}; | |
let data = await create_proposal_tx(op_data); | |
const result = await broadcast(data.tx, data.wif); | |
assert(result.error === false); | |
}); | |
it('datetime underflow ', async () => { | |
let op_data = { | |
'creator': username, | |
'receiver': username, | |
'start_date': '1501-09-01T00:00:00', | |
'end_date': '2018-10-01T00:00:00', | |
'daily_pay': '1.000 TBD', | |
'subject': 'very old start date', | |
'permlink': "my-super-proposal" | |
}; | |
let data = await create_proposal_tx(op_data); | |
const result = await broadcast(data.tx, data.wif); | |
assert(result.error === false); | |
}); | |
it('Proposal start date is far in the future', async () => { | |
let op_data = { | |
'creator': username, | |
'receiver': username, | |
'start_date': '2040-09-01T00:00:00', | |
'end_date': '2041-10-01T00:00:00', | |
'daily_pay': '1.000 TBD', | |
'subject': 'very old start date', | |
'permlink': "my-super-proposal" | |
}; | |
let data = await create_proposal_tx(op_data); | |
const result = await broadcast(data.tx, data.wif); | |
assert(result.error === false); | |
}); | |
it('Proposal duration is less than a day', async () => { | |
let op_data = { | |
'creator': username, | |
'receiver': username, | |
'start_date': '2019-09-01T00:00:00', | |
'end_date': '2019-09-01T23:00:00', | |
'daily_pay': '1.000 TBD', | |
'subject': 'very old start date', | |
'permlink': "my-super-proposal" | |
}; | |
let data = await create_proposal_tx(op_data); | |
const result = await broadcast(data.tx, data.wif); | |
// Shouldn't happen ? | |
assert(result.error === false); | |
}); | |
it('Proposal duration is less than an hour', async () => { | |
let op_data = { | |
'creator': username, | |
'receiver': username, | |
'start_date': '2019-09-01T00:00:00', | |
'end_date': '2019-09-01T01:00:00', | |
'daily_pay': '1.000 TBD', | |
'subject': 'very old start date', | |
'permlink': "my-super-proposal" | |
}; | |
let data = await create_proposal_tx(op_data); | |
const result = await broadcast(data.tx, data.wif); | |
// Shouldn't happen ? | |
assert(result.error === false); | |
}); | |
}); | |
describe('proposal vote', () => { | |
it('vote on proposals', async () => { | |
const wif = steem.auth.toWif(username, password, 'active'); | |
let ops = []; | |
ops.push(['update_proposal_votes', { | |
'voter': username, | |
"proposal_ids" : [28, 2], | |
"approve" : true | |
}]); | |
let tx = {operations: ops, extensions: []}; | |
const result = await broadcast(tx, wif); | |
assert(result.error); | |
}); | |
it('remove votes on one', async () => { | |
const wif = steem.auth.toWif(username, password, 'active'); | |
let ops = []; | |
ops.push(['update_proposal_votes', { | |
'voter': username, | |
"proposal_ids" : [2], | |
"approve" : false | |
}]); | |
let tx = {operations: ops, extensions: []}; | |
const result = await broadcast(tx, wif); | |
assert(result.error); | |
}); | |
it('vote with no proposal_id', async () => { | |
const wif = steem.auth.toWif(username, password, 'active'); | |
let ops = []; | |
ops.push(['update_proposal_votes', { | |
'voter': username, | |
"proposal_ids" : [], | |
"approve" : true | |
}]); | |
let tx = {operations: ops, extensions: []}; | |
const result = await broadcast(tx, wif); | |
assert(result.error === false); | |
}); | |
it('vote nonexistent proposal id', async () => { | |
const wif = steem.auth.toWif(username, password, 'active'); | |
let ops = []; | |
ops.push(['update_proposal_votes', { | |
'voter': username, | |
"proposal_ids" : [-1], | |
"approve" : true | |
}]); | |
let tx = {operations: ops, extensions: []}; | |
const result = await broadcast(tx, wif); | |
assert(result.error === false); | |
}); | |
it('vote with an id that overflows', async () => { | |
const wif = steem.auth.toWif(username, password, 'active'); | |
let ops = []; | |
ops.push(['update_proposal_votes', { | |
'voter': username, | |
"proposal_ids" : [99999999999999999999999999999999999999999999999999], | |
"approve" : true | |
}]); | |
let tx = {operations: ops, extensions: []}; | |
const result = await broadcast(tx, wif); | |
assert(result.error === false); | |
});it('array with existing and nonexisting ids', async () => { | |
const wif = steem.auth.toWif(username, password, 'active'); | |
let ops = []; | |
ops.push(['update_proposal_votes', { | |
'voter': username, | |
"proposal_ids" : [1, 2, 3, 9879879879, 28, -1], | |
"approve" : true | |
}]); | |
let tx = {operations: ops, extensions: []}; | |
const result = await broadcast(tx, wif); | |
assert(result.error === false); | |
}); | |
}); | |
describe('remove proposal', () => { | |
it('remove proposal', async () => { | |
const wif = steem.auth.toWif(username, password, 'active'); | |
let ops = []; | |
ops.push(['remove_proposal', { | |
'proposal_owner': username, | |
"proposal_ids": [28], | |
}]); | |
let tx = {operations: ops, extensions: []}; | |
const result = await broadcast(tx, wif); | |
assert(result.error); | |
}); | |
it('remove proposal that has already been removed', async () => { | |
const wif = steem.auth.toWif(username, password, 'active'); | |
let ops = []; | |
ops.push(['remove_proposal', { | |
'proposal_owner': username, | |
"proposal_ids": [28], | |
}]); | |
let tx = {operations: ops, extensions: []}; | |
const result = await broadcast(tx, wif); | |
// Was expecting not to be able to remove the same proposals several times in a row | |
assert(result.error == false); | |
}); | |
it('remove proposal that I do not own', async () => { | |
const wif = steem.auth.toWif(username, password, 'active'); | |
let ops = []; | |
ops.push(['remove_proposal', { | |
'proposal_owner': username, | |
"proposal_ids": [1], | |
}]); | |
let tx = {operations: ops, extensions: []}; | |
const result = await broadcast(tx, wif); | |
// Was expecting not to be able to remove the same proposals several times in a row | |
assert(result.error == false); | |
}); | |
it('remove several proposals that I own', async () => { | |
const wif = steem.auth.toWif(username, password, 'active'); | |
let ops = []; | |
ops.push(['remove_proposal', { | |
'proposal_owner': username, | |
"proposal_ids": [28,29], | |
}]); | |
let tx = {operations: ops, extensions: []}; | |
const result = await broadcast(tx, wif); | |
assert(result.error); | |
}); | |
it('remove several proposals including one I don\'t own', async () => { | |
const wif = steem.auth.toWif(username, password, 'active'); | |
let ops = []; | |
ops.push(['remove_proposal', { | |
'proposal_owner': username, | |
"proposal_ids": [28,1,29], | |
}]); | |
let tx = {operations: ops, extensions: []}; | |
const result = await broadcast(tx, wif); | |
assert(result.error === false); | |
});it('remove a proposal that doesn\'t exists', async () => { | |
const wif = steem.auth.toWif(username, password, 'active'); | |
let ops = []; | |
ops.push(['remove_proposal', { | |
'proposal_owner': username, | |
"proposal_ids": [500], | |
}]); | |
let tx = {operations: ops, extensions: []}; | |
const result = await broadcast(tx, wif); | |
assert(result.error); | |
}); | |
}); | |
} | |
function create_posts_with_sps_benefs() { | |
const wif = steem.auth.toWif(username, password, 'posting'); | |
const extensions = [[0, { | |
"beneficiaries": [{"account":"steem.dao", "weight": 10000}] | |
}]]; | |
let ops = []; | |
ops.push(['comment', { | |
wif: wif, | |
parent_author: '', | |
parent_permlink: "dao", | |
author: username, | |
permlink: "permlink", | |
title: "100% benef to the dao", | |
body: "100% benef to the dao", | |
json_metadata: "{}" | |
}]); | |
ops.push(['comment_options', { | |
author: username, | |
permlink: "permlink", | |
max_accepted_payout: "1000000.000 TBD", | |
percent_steem_dollars: 10000, | |
allow_votes: true, | |
allow_curation_rewards: true, | |
extensions: extensions | |
}]); | |
steem.broadcast.send({operations: ops, extensions: []}, {posting: wif}, async function (err) { | |
if (!err) { | |
console.log(username + " published the post "); | |
} else { | |
console.log(err); | |
} | |
}); | |
} | |
test(); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment