Added Basic Tests to SteemJs Editor
I've added some basic tests to steemjs editor and it should automatically run those tests when the page opens. The query paramter steemjs supports users-input which means you can pass any values on URL (not limited to those version strings shown in the dropdown list). @ety001
This should give you some confidence of using a version:
// Press Ctrl + Enter to Evaluate
// Press Alt + Backspace to Clear Console
steem.api.getAccounts(['justyy', 'ety001'], function(err, result) {
if (!err) {
for (let i = 0; i < result.length; ++ i) {
let reputation = result[i].reputation;
let formatted_rep = steem.formatter.reputation(reputation);
log(result[i].name + "'s Reputation is " + formatted_rep);
}
} else {
log("Steem API Error: ", err);
}
});
/*
Example of using dSteem
*/
let username = "test";
let password = "password";
log(dsteem.PrivateKey.fromLogin(username, password, 'owner').createPublic());
// ============================================================================
// Mini SteemJS Test Suite (using real steem object)
// ============================================================================
// steem object must already exist globally
// log() must exist — or define fallback:
if (typeof log === "undefined") {
global.log = (...args) => console.log(...args);
}
// Promise wrapper for steem.api
function steemCall(method, params) {
return new Promise((resolve, reject) => {
steem.api[method](...params, (err, result) => {
if (err) reject(err);
else resolve(result);
});
});
}
// Promise wrapper for generic RPC calls
function steemRpcCall(method, params) {
return new Promise((resolve, reject) => {
steem.api.call(method, params, (err, result) => {
if (err) reject(err);
else resolve(result);
});
});
}
// Test registry
const tests = [];
function addTest(name, fn) {
tests.push({ name, fn });
}
// ============================================================================
// 1. Basic positive API tests
// ============================================================================
addTest("steem.api.getAccounts", async () => {
const accounts = await steemCall("getAccounts", [["justyy"]]);
if (accounts && accounts[0] && accounts[0].name === "justyy") return;
throw new Error("Account not returned");
});
addTest("steem.formatter.reputation", async () => {
const rep = steem.formatter.reputation("352352352352");
if (typeof rep === "number") return;
throw new Error("Formatter did not return number");
});
addTest("steem.api.getDynamicGlobalProperties", async () => {
const props = await steemCall("getDynamicGlobalProperties", []);
if (props && props.head_block_number) return;
throw new Error("Missing head_block_number");
});
addTest("steem.api.getChainProperties", async () => {
await steemCall("getChainProperties", []);
});
addTest("steem.api.getConfig", async () => {
await steemCall("getConfig", []);
});
addTest("steem.api.getRewardFund", async () => {
const fund = await steemCall("getRewardFund", ["post"]);
if (fund && fund.reward_balance) return;
throw new Error("Reward fund missing");
});
addTest("steem.api.getCurrentMedianHistoryPrice", async () => {
const price = await steemCall("getCurrentMedianHistoryPrice", []);
if (price && price.base) return;
throw new Error("Missing price");
});
addTest("steem.api.getAccountHistory", async () => {
const hist = await steemCall("getAccountHistory", ["justyy", -1, 1]);
if (Array.isArray(hist)) return;
throw new Error("History not an array");
});
addTest("steem.api.getDiscussionsByCreated", async () => {
const posts = await steemCall("getDiscussionsByCreated", [{ tag: "steem", limit: 1 }]);
if (Array.isArray(posts)) return;
throw new Error("Posts not array");
});
addTest("steem.api.getTrendingTags", async () => {
const tags = await steemCall("getTrendingTags", ["steem", 1]);
if (Array.isArray(tags)) return;
throw new Error("Tags not array");
});
// ============================================================================
// 2. Negative tests
// ============================================================================
addTest("Negative invalid method name", async () => {
try {
await steemRpcCall("NON_EXISTENT_METHOD", {});
} catch {
return; // PASS
}
throw new Error("Invalid method unexpectedly succeeded");
});
addTest("Negative invalid history range", async () => {
try {
await steemCall("getAccountHistory", ["justyy", 999999999, -5]);
} catch {
return; // PASS
}
throw new Error("Invalid history range unexpectedly succeeded");
});
// ============================================================================
// Test Runner
// ============================================================================
async function runTests() {
log("Starting SteemJS test suite...");
for (const t of tests) {
try {
await t.fn();
log(`✅Test passed: ${t.name}`);
} catch (err) {
log(`❌Test failed: ${t.name} (${err.message || err})`);
}
}
log("Finished.")
}
runTests();
Steem to the Moon🚀!
- You can rent Steem Power via rentsp!
- You can swap the TRON:TRX/USDT/USDD to STEEM via tron2steem!
- You can swap the STEEM/SBD to SUI via steem2sui!
- You can swap the STEEM/SBD to SOL Solana via steem2sol!
- You can swap the STEEM/SBD to ETH Ethereum via steem2eth!
- You can swap the STEEM/SBD to Tether USDT (TRC-20) via steem2usdt!
- You can swap the STEEM/SBD to TRX (TRON) via steem2trx!
- You can swap the STEEM/SBD to BTS (BitShares) via steem2bts!
- Register a free STEEM account at SteemYY!
- Steem Block Explorer
- ChatGPT/Steem Integration: You can type !ask command to invoke ChatGPT
- Steem Witness Table and API
- Other Steem Tools
Support me, thank you!
Why you should vote me? My contributions
Please vote me as a witness or set me as a proxy via https://steemitwallet.com/~witnesses



