Skip to main content

PREDA Test Script Syntax

Allocate address

Description:

Generate specific number of addresses, The actual number of addresses applied for conforms to the following formula:

{actual_number=shardnshard(n1)<=specific_number<=shardn\begin{cases} actual\_number = shard * n\\ shard * (n-1)<= specific\_number <= shard * n\\ \end{cases}
  • shard: the number of shards

  • n: positive integer

Command:

allocate.address [address_number]

Parameter:

  • address_number: the number of addresses to be generated

Example:

allocate.address 10

Output:

12 addresses added and evenly distributed in shards

Specify address

Description:

Use the Allocated address in the test script

Command:

@address_order
@all
@random

Parameter:

  • address_order:address order n, random, all, represents the number n+1th address, random address, and all addresses respectively.

Example:

// address_0 initiate a vote
Ballot.init @0 { names: ["Spring", "Yarn", "Combat"] }
// all address vote
Ballot.vote @all { proposal_index: $random(0,2)$, case_num: 1 }
// a random address vote
Ballot.vote @random { proposal_index: $random(0,2)$, case_num: 1 }

Random

Description:

The PREDA-Toolchain provides some functions related to random numbers, for example, specify random address or specify a random input parameter.

First at all, we should specify a seed for random.

Command:

random.reseed [seed]

Parameters:

  • seed: the default seed is timestamp, but you can set as any value manually

Example:

// set the random seed
random.reseed 88
// specify a random address when call a contract function
Ballot.init @random { names: ["Spring", "Yarn", "Combat"] }
// specify a random input parameter between 0 and 2
Ballot.vote @0 { proposal_index: $random(0,2)$, case_num: 1 }

Set gas limit

Description:

Set the gas limit which is the maximum amount of gas that transactions in a block can consume.

Command:

chain.gaslimit [limit]

Parameters:

  • limit: the limit for all transaction's gaslimit in a block

Example:

chain.gaslimit 128

Deploy smart contracts

Description:

Deploy smart contracts, multiple contracts can be deployed.

Command:

chain.deploy @address_order [contract_file] [*contract_file]

Parameters:

  • contract_file: the name of the contract file, which supports multiple names to be set at the same time, with space-separated.
  • address_order: the order of the address that initiated the contract deployment.

Example:

chain.deploy @0 SimpleStorage.prd

Output:

Compiling 1 contract code(s) ...
contract `SimpleStorage`: 2 function(s) with states in address scope(s)
0) SimpleStorage.increment: txn
1) SimpleStorage.decrement: txn
Linking and deploying ...
[PRD]: Successfully deployed 1 contract(s)

Set contract states

Description:

Set the state for the blockchain, which is used to initialize the contract state. Users need set all variable when set shard or global states.

Command:

  • Set the global state
state.set global.contract_name { state_name:state_value } 
  • Set the shard state
state.set shard.contract_name @shard_order { state_name:state_value } 
  • Set the address state
state.set address.contract_name @address_order { state_name:state_value } 

Parameters:

  • contract_name: the name of the contract
  • shard_order: the serial number for shard
  • address_order: the serial number for address
  • state_name: the name of the state to be set
  • state_value: the value of the state to be set

Example:

Set the global state

state.set global.Ballot { controller:"$@0$", current_case:0, proposals:[], last_result:{topVoted:"",case:0}, shardGatherRatio:0}

Set the shard state

state.set shard.Ballot #all { votedWeights:[] }

Set the address state

state.set address.Ballot @all { weight:$random(1, 20)$, voted_case:0 } 

Call a contract function

Description:

Call a contract function and generate the transaction into mempool .

Command:

// call a global function
contract_name.contract_function[*call_number] contract_params
// call a shard function
contract_name.contract_function[*call_number] #shard_order contract_params
// call a address function
contract_name.contract_function[*call_number] @address_order contract_params

Parameters:

  • contract_name: the name of the contract
  • contract_function: the name of the contract function
  • call_number: the number of call times, which is an optional parameter
  • shard_order: the serial number for shard, users can also use #all to specify shard
  • address_order: the serial number for address, users can also use @random and @all to specify address
  • contract_params: contract input parameters

Example:

// call a global function
KittyBreeding.mint*3 { genes: "$bigint.random(32)$", gender: true, owner: "$@all$" }
// call a shard function
KittyBreeding.registerNewBorns #all {}
// call a address function
KittyBreeding.breed*$~count$ @random { m: $random(1, ~count-1)$, s: $random(~count+1, ~count*2-1)$, gender : false }

Run the blockchain

Description:

Run the blockchain to execute transanctions in the mempool, then add them to block until each shard is archived.

Command:

chain.run

Example:

chain.run

Get chain info

Description:

Output the number of transactions and addresses of current shard in the blockchain.

Command:

chain.info

Example:

chain.info

Output:

Global: h:0 txn:0/0/0 addr:0
Shd#0: h:0 txn:17/0/0 addr:25
Shd#1: h:0 txn:31/0/0 addr:25
Shd#2: h:0 txn:23/0/0 addr:25
Shd#3: h:0 txn:29/0/0 addr:25
Total Txn:100/0

log

Description:

Print log or print highlight log

Command:

log text
log.highlight text

Parameters:

  • text: content of the log

Example:

log this is log
log.highlight this is highlight log

Output:

image-20221212193231433

stopwatch

Description:

Test contract performance with stopwatch.

Command:

stopwatch.restart
stopwatch.report

Example:

stopwatch.restart
chain.run
stopwatch.report

Output:

Stopwatch: 5 msec
Order: 2, TPS:20000, uTPS:20000

Visualization

viz.block

Description:

Display block information in the visual interface

Command:

// Display the block information of the specified shard
viz.block #shard_order
// Display the block information of the specified shard and block height
viz.block #shard_order:height
// Display the block information of all shard
viz.block #all
// Display the block information of global shard
viz.block #g

Parameters:

  • shard_order: the order of shards
  • height: the block height

Example:

viz.block #1:2

Output:

image-20221212194300915

Example:

log.block #g

Output:

image-20221212194323576

viz.shard

Description:

Display shard states in the visual interface

Command:

// Display the shard states of the specified shard
viz.shard #shard_order
// Display the global states
viz.shard #g
// Display all shard states
viz.shard #all
// Display the shard states of the specified shard and contract
viz.shard #shard contract_name

Parameters:

  • shard_order: the order of shards
  • contract_name: the name of contract

Example:

viz.shard #all

Output:

image-20221212194745404

Example:

viz.shard #g

Output:

image-20221212194809958

Example:

viz.shard #1 Ballot

Output:

image-20221212194859742

viz.addr

Description:

Display address states in the visual interface

Command:

// Display the address states of the specified address
viz.addr @address_order
// Display all address states
viz.shard @all
// Display a random address states
viz.shard @random
// Display the address states of the specified address and contract
viz.shard @address_order contract_name

Parameters:

  • address_order: the order of addresses
  • contract_name: the name of contract

Example:

viz.addr @random

Output:

image-20221212200023796

Example:

viz.addr @3 Ballot

Output:

image-20221212200753823

Example:

viz.addr @all

Output:

image-20221212200807947

viz.txn

Description:

Display transaction information in the visual interface

Command:

viz.txn txn_name

Parameters:

  • txn_name: identifies a contract method call, which cannot be repeated

Example:

txn1 = Ballot.init @0 { names: ["Spring", "Yarn", "Combat"] } 
chain.run
viz.txn txn1

Output:

image-20221212204401759

Example:

txn2[] = Ballot.vote @all { proposal_index: $random(0,2)$, case_num: 1 } 
chain.run
viz.txn txn2[0]

Output:

image-20221212204455311

viz.trace

Description:

Display the transaction call chain in the visual interface

Command:

viz.trace txn_name

Parameters:

  • txn_name: identifies a contract method call, which cannot be repeated

Example:

txn3 = Ballot.finalize @0 {} 
chain.run
viz.trace txn3

Output:

image-20221212204643748

viz.section

Description:

Display section information in the visual interface

Command:

viz.section section_name

Parameters:

  • section_name: the name of section

Example:

viz.section Finalize

Output:

image-20221212204958982

viz.profiling

Description:

Display performance information in the visual interface, this information relies on the statistics of the stopwatch.

Command:

viz.profiling

Example:

viz.profiling

Output:

image-20221212205421654