docs on readonly testing and using the readonly transaction

This commit is contained in:
Eric Passmore
2023-05-26 21:27:05 -07:00
parent 6219bca4f9
commit 40774e1aa8
6 changed files with 40 additions and 96 deletions
+6 -3
View File
@@ -82,8 +82,7 @@ Importing using commonJS syntax is supported by NodeJS out of the box.
```js
const { Api, JsonRpc, RpcError } = require('enf-eosjs');
const fetch = require('node-fetch'); // node only; not needed in browsers
const { TextEncoder, TextDecoder } = require('util'); // node only; native TextEncoder/Decoder
const { TextEncoder, TextDecoder } = require('util'); // React Native, IE11, and Edge Browsers only
const { TextEncoder, TextDecoder } = require('util'); // native TextEncoder/Decoder
```
## Basic Usage
@@ -117,7 +116,7 @@ const api = new Api({ rpc, signatureProvider, textDecoder: new TextDecoder(), te
`transact()` is used to sign and push transactions onto the blockchain with an optional configuration object parameter. This parameter can override the default value of `broadcast: true`, and can be used to fill TAPOS fields given `blocksBehind` and `expireSeconds`. Given no configuration options, transactions are expected to be unpacked with TAPOS fields (`expiration`, `ref_block_num`, `ref_block_prefix`) and will automatically be broadcast onto the chain.
With the introduction of Mandel v3.1 the retry transaction feature also adds 5 new optional fields to the configuration object:
With the introduction of Antelope v3.1 the retry transaction feature also adds 5 new optional fields to the configuration object:
- `useOldRPC`: use old RPC `push_transaction`, rather than new RPC send_transaction
- `useOldSendRPC`: use old RPC `/v1/chain/send_transaction`, rather than new RPC `/v1/chain/send_transaction2`
@@ -125,6 +124,10 @@ With the introduction of Mandel v3.1 the retry transaction feature also adds 5 n
- `retryTrxNumBlocks`: request node to retry transaction until in a block of given height, blocking call
- `retryIrreversible`: request node to retry transaction until it is irreversible or expires, blocking call
With the introduction of Antelope v4.0 the read only transaction feature adds a new optional field to the configuration object:
- `readOnly` : send read only transaction, using `/v1/chain/send_read_only_transaction`.
```js
(async () => {
const result = await api.transact({
-81
View File
@@ -1,81 +0,0 @@
# Testing and Building with DUNE
DUNE makes it easier to test locally. Performing integration tests with DUNE requires some setup.
[DUNE may be installed from git hub](https://github.com/eosnetworkfoundation/DUNE)
## Open Local Node Port
Need to change **scripts/config.ini** from `http-server-address = 127.0.0.1:8888` to `http-server-address = 0.0.0.0:8888`. This will enable port 8888 to listen on all ports, and that is needed because docker runs on a different network.
This is part of the docker image, so this must be completed before running `bootstrap`. If you already have a docker image you can
* Destroy the docker container
* Remove docker image
* Re-run bootstrap
An alternative option is to enter the docker container, change the configuration, and restart the node.
## DUNE Keys
Once you follow the directions you need to grap the keys for the existing eosio account.
```
egrep 'priv_key|pub_key' src/dune/*.py
```
## Start a Node
Start a node if you haven't already
```
dune --start test_node
```
## Create Wallet
Start a Docker shell. Must be done locally due to permission problems with DUNE.
```
docker exec -it dune_container /bin/bash
```
Commands to make wallet
```
cleos wallet create -n bob -f jungle4-wallet/bob.wallet
cleos wallet unlock -n bobtestlion1 --password $(cat jungle4-wallet/bob.wallet)
```
## Create Accounts
Now we can create our test accounts. In the examples below replace, **priv_key** and **pub_key** with the values from [DUNE Keys](#DUNE Keys)
```
dune --create-key
dune --create-account bob eosio pub_key priv_key
dune --create-key
dune --create-account alice eosio pub_key priv_key
```
## Add Private Key to Wallet
Use bob's priv_key
Note done locally
```
cleos wallet import -n bobtestlion1 --private-key priv_key
```
## Test Transfer
Note done locally
```
cleos transfer bob alice "0.001 EOS" "Hodl!" -p bob
```
## Private Keys in Tests
Look at `src/tests/node.js` and `src/tests/web.html` to make sure the private key matches DUNE's.
## Run Tests
```
npm run test node
```
If you want just the integration tests run.
```angular2html
npm run test-node
```
+32 -3
View File
@@ -1,3 +1,32 @@
The read only contract requires a special contract. You can find the source code under `src/tests/readonly_contract`.
Once compiled the contracted is loaded via the command `cleos -u https://jungle4.cryptolions.io set contract hokieshokies ./ contract.wasm contract.abi`
The action on `read-only` test will refer to `mycontract`, and with the contract loaded you will be able to run the test
## Testing Read Only
Performing a read only transaction requires an action that does not modify the blockchain. To facilitate testing a simple read only contract is included in the test directory.
## The Read Only Contract
You can find the source code under `src/tests/readonly_contract`. The contract returns a single numeric value.
## Compile the Contract
Use `cdt-cpp` to compile this will produce two files one *.abi file and a *.wasm file
```shell
cd tests/readonly_contract
cdt-cpp --abigen -o simplereadonlycontract.wasm simplereadonlycontract.cpp
```
## Load The Contract
Loading the **Action Return Value**. You will need to make sure the action return value feature is avalible.
```shell
cleos push action eosio activate '["c3a6138c5061cf291310887c0b5c71fcaffeab90d5deb50d3b9e687cead45071"]' -p eosio
```
Once the feature is activated, you may load the contract.
```shell
cd tests
cleos -u http://127.0.0.1:8888/ set contract hokieshokies ./simplereadonlycontract -p hokieshokies@active
```
## Running The Contract
Once the contract is loaded the action `getvalue` in the account scope `hokieshokies` will work as a read only transaction.
+1 -8
View File
@@ -7,14 +7,7 @@ const { TestConfig, TestNet } = require('./TestConfig.ts');
const privateKey = '5JJBHqug5hX1cH91R5u3oMiA3ncHYW395PPmHQbfUshJikGDCBv';
const testActor = 'hokieshokies'
const testRecipient = 'alicetestlio'
/* new accounts for testing can be created
* see docs/5.-Testing and Building with DUNE.md
* OR by unlocking a cleos wallet then calling:
* 1) cleos create key --to-console (copy this privateKey & publicKey)
* 2) cleos wallet import
* 3) cleos create account bob publicKey
* 4) cleos create account alice publicKey
*/
/* new accounts for testing can be created */
// TestNet.Local or TestNet.Jungle sets endpoint, blocksBehind, and expireSeconds
const config = new TestConfig(TestNet.Jungle);
@@ -5,7 +5,7 @@ using namespace eosio;
// If you're just learning follow our Getting Started guide here:
// https://docs.eosnetwork.com/docs/latest/smart-contracts/getting-started/smart_contract_basics
CONTRACT mycontract : public contract {
CONTRACT simplereadonlycontract : public contract {
public:
using contract::contract;