मुख्य सामग्री पर जाएं
अपने Web3 Action code के local development को सुविधाजनक बनाने के लिए, आप @tenderly/actions-test package (tenderly-actions में शामिल) का उपयोग कर सकते हैं। यह एक Tenderly runtime उजागर करता है, ताकि आप अपने local environment में अपनी Web3 Action को execute और शायद test कर सकें। अपने Web3 Action functions को locally test करने के लिए @tenderly/actions-test package स्थापित करें।
example
yarn add --dev @tenderly/actions-test
web3-actions project के size को बढ़ाने से बचने के लिए, web3-actions के लिए tests और run scripts को actions root directory के बाहर रखने की सिफारिश की जाती है।
आप @tenderly/actions-test का उपयोग अपने development process का समर्थन करने के लिए दो तरीकों से कर सकते हैं:
  • इसे अपने automated tests के भीतर उपयोग करें (अनुशंसित)।
  • JavaScript/TypeScript में एक run script बनाएँ।

अपने tests में @tenderly/actions-test का उपयोग करना

अपने tests में @tenderly/actions-test का उपयोग करने के लिए, कोई अतिरिक्त चरणों की आवश्यकता नहीं है। अपनी Web3 Action का परीक्षण करने और परिणामों को assert करने के लिए आवश्यक TestRuntime और events को import करें। निम्नलिखित उदाहरण दिखाते हैं कि package का उपयोग Web3 Action को invoke करने और Action functions जो event object की अपेक्षा करती हैं उसे पास करने के लिए कैसे किया जाए। आप जिन event types को पास कर सकते हैं, उनके विवरण के लिए, functions, events, और triggers देखें।

एक कार्यशील उदाहरण

multisig wallet उदाहरण और इसका उपयोग यह करने के तरीके को देखें कि @tenderly/actions-test का उपयोग locally action function चलाने के लिए कैसे किया जाता है।

Running the action function locally

उदाहरण: एक script के भीतर Action function चलाना

निम्न उदाहरण src/web3-actions-local/run.ts पर एक file दिखाता है जो तीन actions चलाती है, उपयुक्त events पास करते हुए। ध्यान दें कि Web3 Actions source file (src/actions/awesomeActions.ts) script वाली directory के sibling में है:

चरण 1: run script लिखें

example.tsx
// File: src/web3-actions-local/run.ts
// web3-actions sources location: src/actions/awesomeActions.ts


/*
 * Running Web3 Actions code locally.
 * TestRuntime is a helper class that allows you to run the functions,
 * and set storage and secrets before running the function
 **/
const main = async () => {
  const testRuntime = new TestRuntime();

  testRuntime.context.secrets.put('multisig.DISCORD_URL', process.env.DISCORD_URL || '');

  await testRuntime.execute(everyDay, new TestPeriodicEvent());

  await testRuntime.execute(whenDappPosts, new TestWebhookEvent({ foo: 'bar' }));

  const te = new TestTransactionEvent();
  te.to = '0x1a22...';
  te.from = '0xc023...';

  await testRuntime.execute(onTxEvent, new TransactionEvent());
};

(async () => await main())();

चरण 2: enclosing project के package.json में scripts का विस्तार करें।

आप इस script को अपनी package.json file में जोड़ सकते हैं।
example
{
    ...
  "scripts": {
    ...
+   "local-w3a-run": "ts-node src/web3-actions-local/run.ts"
    ...
  }
  ...
}

चरण 3: script चलाएँ

example
yarn local-w3a-run