@_koi/smartest 中文文档教程

发布于 3年前 浏览 17 项目主页 更新于 3年前

smartest

本地SmartWeave模拟

Usage

  • smartest.readContractState(contractId)
    • Read state from env
  • smartest.writeContractState(contractId, state)
    • Write state to env
  • await smartest.interactWrite(arweave, contractSrc, wallet, contractInput, contractState, walletAddress, contractId, contractOwner=null)
    • Execute contract and write state to env

Example

// import smartest
const smartest = require("@_koi/smartest");

// set the initial state
const tallyInitState = JSON.parse(
    fs.readFileSync(`test/tally_init_state.json`)
);
smartest.writeContractState(tallyContractId, tallyInitState);

// Load tally contract and prepare input
const tallySrc = fs.readFileSync(`test/tally.js`, "utf8");
const tallyContractId = "q5w6e7r8";
const tallyInput = {
    function: "tally",
    rngContractId: rngContractId
};

// Interact write contract
await smartest.interactWrite(
    arweave,
    tallySrc,
    wallet,
    tallyInput,
    smartest.readContractState(tallyContractId),
    walletAddress,
    tallyContractId
);

// Inspect output
console.log(smartest.readContractState(tallyContractId));

Testing

节点测试路径/to/wallet.json

Notes

  • Smartest is locked to SmartWeave 0.4.31 or earlier as later versions use arweave.blocks.getCurrent() in interactWriteDryRun which breaks smartest

smartest

Local SmartWeave simulation

Usage

  • smartest.readContractState(contractId)
    • Read state from env
  • smartest.writeContractState(contractId, state)
    • Write state to env
  • await smartest.interactWrite(arweave, contractSrc, wallet, contractInput, contractState, walletAddress, contractId, contractOwner=null)
    • Execute contract and write state to env

Example

// import smartest
const smartest = require("@_koi/smartest");

// set the initial state
const tallyInitState = JSON.parse(
    fs.readFileSync(`test/tally_init_state.json`)
);
smartest.writeContractState(tallyContractId, tallyInitState);

// Load tally contract and prepare input
const tallySrc = fs.readFileSync(`test/tally.js`, "utf8");
const tallyContractId = "q5w6e7r8";
const tallyInput = {
    function: "tally",
    rngContractId: rngContractId
};

// Interact write contract
await smartest.interactWrite(
    arweave,
    tallySrc,
    wallet,
    tallyInput,
    smartest.readContractState(tallyContractId),
    walletAddress,
    tallyContractId
);

// Inspect output
console.log(smartest.readContractState(tallyContractId));

Testing

node test path/to/wallet.json

Notes

  • Smartest is locked to SmartWeave 0.4.31 or earlier as later versions use arweave.blocks.getCurrent() in interactWriteDryRun which breaks smartest
    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文