Skip to main content

IntegrationTestRpc

Trait IntegrationTestRpc 

Source
pub trait IntegrationTestRpc {
    // Required methods
    fn process_block_without_verify(
        &self,
        data: Block,
        broadcast: bool,
    ) -> Result<Option<H256>>;
    fn truncate(&self, target_tip_hash: H256) -> Result<()>;
    fn generate_block(&self) -> Result<H256>;
    fn generate_epochs(
        &self,
        num_epochs: EpochNumberWithFraction,
    ) -> Result<EpochNumberWithFraction>;
    fn notify_transaction(&self, transaction: Transaction) -> Result<H256>;
    fn generate_block_with_template(
        &self,
        block_template: BlockTemplate,
    ) -> Result<H256>;
    fn calculate_dao_field(
        &self,
        block_template: BlockTemplate,
    ) -> Result<Byte32>;
    fn send_test_transaction(
        &self,
        tx: Transaction,
        outputs_validator: Option<OutputsValidator>,
    ) -> Result<H256>;
}
Expand description

RPC for Integration Test.

Required Methods§

Source

fn process_block_without_verify( &self, data: Block, broadcast: bool, ) -> Result<Option<H256>>

process block without any block verification.

§Params
  • data - block data(in binary).

  • broadcast - true to enable broadcast(relay) the block to other peers.

§Examples

Request

{
  "id": 42,
  "jsonrpc": "2.0",
  "method": "process_block_without_verify",
  "params": [
   {
	"header": {
		"compact_target": "0x1e083126",
		"dao": "0xb5a3e047474401001bc476b9ee573000c0c387962a38000000febffacf030000",
		"epoch": "0x7080018000001",
		"extra_hash": "0x0000000000000000000000000000000000000000000000000000000000000000",
		"nonce": "0x0",
		"number": "0x400",
		"parent_hash": "0xae003585fa15309b30b31aed3dcf385e9472c3c3e93746a6c4540629a6a1ed2d",
		"proposals_hash": "0x0000000000000000000000000000000000000000000000000000000000000000",
		"timestamp": "0x5cd2b117",
		"transactions_root": "0xc47d5b78b3c4c4c853e2a32810818940d0ee403423bea9ec7b8e566d9595206c",
		"version": "0x0"
	},
	"proposals": [],
	"transactions": [{
		"cell_deps": [],
		"header_deps": [],
		"inputs": [{
			"previous_output": {
				"index": "0xffffffff",
				"tx_hash": "0x0000000000000000000000000000000000000000000000000000000000000000"
			},
			"since": "0x400"
		}],
		"outputs": [{
			"capacity": "0x18e64b61cf",
			"lock": {
				"code_hash": "0x28e83a1277d48add8e72fadaa9248559e1b632bab2bd60b27955ebc4c03800a5",
				"hash_type": "data",
				"args": "0x"
			},
			"type": null
		}],
		"outputs_data": [
			"0x"
		],
		"version": "0x0",
		"witnesses": [
			"0x450000000c000000410000003500000010000000300000003100000028e83a1277d48add8e72fadaa9248559e1b632bab2bd60b27955ebc4c03800a5000000000000000000"
		]
	}],
	"uncles": []
    },
    true
  ]
}

Response

{
  "id": 42,
  "jsonrpc": "2.0",
  "result": "0xa5f5c85987a15de25661e5a214f2c1449cd803f071acc7999820f25246471f40"
}
Source

fn truncate(&self, target_tip_hash: H256) -> Result<()>

Truncate chain to specified tip hash, can only truncate less then 50000 blocks each time.

§Params
  • target_tip_hash - specified header hash
§Examples

Request

{
  "id": 42,
  "jsonrpc": "2.0",
  "method": "truncate",
  "params": [
    "0xa5f5c85987a15de25661e5a214f2c1449cd803f071acc7999820f25246471f40"
  ]
}

Response

{
  "id": 42,
  "jsonrpc": "2.0",
  "result": null
}
Source

fn generate_block(&self) -> Result<H256>

Generate block(with verification) and broadcast the block.

Note that if called concurrently, it may return the hash of the same block.

§Examples

Request

{
  "id": 42,
  "jsonrpc": "2.0",
  "method": "generate_block",
  "params": []
}

Response

{
  "id": 42,
  "jsonrpc": "2.0",
  "result": "0x60dd3fa0e81db3ee3ad41cf4ab956eae7e89eb71cd935101c26c4d0652db3029"
}
Source

fn generate_epochs( &self, num_epochs: EpochNumberWithFraction, ) -> Result<EpochNumberWithFraction>

Generate epochs during development, can be useful for scenarios like testing DAO-related functionalities.

Returns the updated epoch number after generating the specified number of epochs.

§Params
  • num_epochs - The number of epochs to generate.
§Examples

Request

Generating 2 epochs:

{
  "id": 42,
  "jsonrpc": "2.0",
  "method": "generate_epochs",
  "params": ["0x2"]
}

The input parameter “0x2” will be normalized to “0x10000000002”(the correct EpochNumberWithFraction type) within the method. Therefore, if you want to generate epochs as integers, you can simply pass an integer as long as it does not exceed 16777215 (24 bits).

Generating 1/2 epoch:

{
  "id": 42,
  "jsonrpc": "2.0",
  "method": "generate_epochs",
  "params": ["0x20001000000"]
}

Response

{
  "id": 42,
  "jsonrpc": "2.0",
  "result": "0xa0001000003"
}
Source

fn notify_transaction(&self, transaction: Transaction) -> Result<H256>

Add transaction to tx-pool.

§Params
  • transaction - specified transaction to add
§Examples

Request

{
	"id": 42,
	"jsonrpc": "2.0",
	"method": "notify_transaction",
	"params":
    [
         {
			"cell_deps": [{
				"dep_type": "code",
				"out_point": {
					"index": "0x0",
					"tx_hash": "0xa4037a893eb48e18ed4ef61034ce26eba9c585f15c9cee102ae58505565eccc3"
				}
			}],
			"header_deps": [
				"0x7978ec7ce5b507cfb52e149e36b1a23f6062ed150503c85bbf825da3599095ed"
			],
			"inputs": [{
				"previous_output": {
					"index": "0x0",
					"tx_hash": "0x365698b50ca0da75dca2c87f9e7b563811d3b5813736b8cc62cc3b106faceb17"
				},
				"since": "0x0"
			}],
			"outputs": [{
				"capacity": "0x2540be400",
				"lock": {
					"code_hash": "0x28e83a1277d48add8e72fadaa9248559e1b632bab2bd60b27955ebc4c03800a5",
					"hash_type": "data",
					"args": "0x"
				},
				"type": null
			}],
			"outputs_data": [
				"0x"
			],
			"version": "0x0",
			"witnesses": []
		}
	]
}

Response

{
  "id": 42,
  "jsonrpc": "2.0",
  "result": "0xa0ef4eb5f4ceeb08a4c8524d84c5da95dce2f608e0ca2ec8091191b0f330c6e3"
}
Source

fn generate_block_with_template( &self, block_template: BlockTemplate, ) -> Result<H256>

Generate block with block template, attach calculated dao field to build new block,

then process block and broadcast the block.

§Params
  • block_template - specified transaction to add
§Examples

Request

{
  "id": 42,
  "jsonrpc": "2.0",
  "method": "generate_block_with_template",
  "params": [
   {
    "bytes_limit": "0x91c08",
    "cellbase": {
      "cycles": null,
      "data": {
        "cell_deps": [],
        "header_deps": [],
        "inputs": [
          {
            "previous_output": {
              "index": "0xffffffff",
              "tx_hash": "0x0000000000000000000000000000000000000000000000000000000000000000"
            },
            "since": "0x401"
          }
        ],
       "outputs": [
         {
           "capacity": "0x18e64efc04",
            "lock": {
              "code_hash": "0x28e83a1277d48add8e72fadaa9248559e1b632bab2bd60b27955ebc4c03800a5",
              "hash_type": "data",
              "args": "0x"
            },
            "type": null
          }
        ],
        "outputs_data": [
          "0x"
        ],
        "version": "0x0",
        "witnesses": [
          "0x650000000c00000055000000490000001000000030000000310000001892ea40d82b53c678ff88312450bbb17e164d7a3e0a90941aa58839f56f8df20114000000b2e61ff569acf041b3c2c17724e2379c581eeac30c00000054455354206d657373616765"
        ]
      },
      "hash": "0xbaf7e4db2fd002f19a597ca1a31dfe8cfe26ed8cebc91f52b75b16a7a5ec8bab"
    },
    "compact_target": "0x1e083126",
    "current_time": "0x174c45e17a3",
    "cycles_limit": "0xd09dc300",
    "dao": "0xd495a106684401001e47c0ae1d5930009449d26e32380000000721efd0030000",
    "epoch": "0x7080019000001",
    "extension": "0xb0a0079f3778c0ba0d89d88b389c602cc18b8a0355d16c0713f8bfcee64b5f84",
    "number": "0x401",
    "parent_hash": "0xa5f5c85987a15de25661e5a214f2c1449cd803f071acc7999820f25246471f40",
    "proposals": ["0xa0ef4eb5f4ceeb08a4c8"],
    "transactions": [],
    "uncles": [
      {
        "hash": "0xdca341a42890536551f99357612cef7148ed471e3b6419d0844a4e400be6ee94",
        "header": {
          "compact_target": "0x1e083126",
          "dao": "0xb5a3e047474401001bc476b9ee573000c0c387962a38000000febffacf030000",
          "epoch": "0x7080018000001",
          "extra_hash": "0x0000000000000000000000000000000000000000000000000000000000000000",
          "nonce": "0x0",
          "number": "0x400",
          "parent_hash": "0xae003585fa15309b30b31aed3dcf385e9472c3c3e93746a6c4540629a6a1ed2d",
          "proposals_hash": "0x0000000000000000000000000000000000000000000000000000000000000000",
          "timestamp": "0x5cd2b118",
          "transactions_root": "0xc47d5b78b3c4c4c853e2a32810818940d0ee403423bea9ec7b8e566d9595206c",
          "version":"0x0"
        },
        "proposals": [],
        "required": false
      }
    ],
    "uncles_count_limit": "0x2",
    "version": "0x0",
    "work_id": "0x0"
   }
 ]
}

Response

{
  "id": 42,
  "jsonrpc": "2.0",
  "result": "0x899541646ae412a99fdbefc081e1a782605a7815998a096af16e51d4df352c75"
}
Source

fn calculate_dao_field(&self, block_template: BlockTemplate) -> Result<Byte32>

Return calculated dao field according to specified block template.

§Params
  • block_template - specified block template
§Examples

Request

{
  "id": 42,
  "jsonrpc": "2.0",
  "method": "calculate_dao_field",
  "params": [
   {
    "bytes_limit": "0x91c08",
    "cellbase": {
      "cycles": null,
      "data": {
        "cell_deps": [],
        "header_deps": [],
        "inputs": [
          {
            "previous_output": {
              "index": "0xffffffff",
              "tx_hash": "0x0000000000000000000000000000000000000000000000000000000000000000"
            },
            "since": "0x401"
          }
        ],
       "outputs": [
         {
           "capacity": "0x18e64efc04",
            "lock": {
              "code_hash": "0x28e83a1277d48add8e72fadaa9248559e1b632bab2bd60b27955ebc4c03800a5",
              "hash_type": "data",
              "args": "0x"
            },
            "type": null
          }
        ],
        "outputs_data": [
          "0x"
        ],
        "version": "0x0",
        "witnesses": [
          "0x650000000c00000055000000490000001000000030000000310000001892ea40d82b53c678ff88312450bbb17e164d7a3e0a90941aa58839f56f8df20114000000b2e61ff569acf041b3c2c17724e2379c581eeac30c00000054455354206d657373616765"
        ]
      },
      "hash": "0xbaf7e4db2fd002f19a597ca1a31dfe8cfe26ed8cebc91f52b75b16a7a5ec8bab"
    },
    "compact_target": "0x1e083126",
    "current_time": "0x174c45e17a3",
    "cycles_limit": "0xd09dc300",
    "dao": "0xd495a106684401001e47c0ae1d5930009449d26e32380000000721efd0030000",
    "epoch": "0x7080019000001",
    "extension": "0xb0a0079f3778c0ba0d89d88b389c602cc18b8a0355d16c0713f8bfcee64b5f84",
    "number": "0x401",
    "parent_hash": "0xa5f5c85987a15de25661e5a214f2c1449cd803f071acc7999820f25246471f40",
    "proposals": ["0xa0ef4eb5f4ceeb08a4c8"],
    "transactions": [],
    "uncles": [
      {
        "hash": "0xdca341a42890536551f99357612cef7148ed471e3b6419d0844a4e400be6ee94",
        "header": {
          "compact_target": "0x1e083126",
          "dao": "0xb5a3e047474401001bc476b9ee573000c0c387962a38000000febffacf030000",
          "epoch": "0x7080018000001",
          "extra_hash": "0x0000000000000000000000000000000000000000000000000000000000000000",
          "nonce": "0x0",
          "number": "0x400",
          "parent_hash": "0xae003585fa15309b30b31aed3dcf385e9472c3c3e93746a6c4540629a6a1ed2d",
          "proposals_hash": "0x0000000000000000000000000000000000000000000000000000000000000000",
          "timestamp": "0x5cd2b118",
          "transactions_root": "0xc47d5b78b3c4c4c853e2a32810818940d0ee403423bea9ec7b8e566d9595206c",
          "version":"0x0"
        },
        "proposals": [],
        "required": false
      }
    ],
    "uncles_count_limit": "0x2",
    "version": "0x0",
    "work_id": "0x0"
   }
  ]
}

Response

{
  "id": 42,
  "jsonrpc": "2.0",
  "result": "0xd495a106684401001e47c0ae1d5930009449d26e32380000000721efd0030000"
}
Source

fn send_test_transaction( &self, tx: Transaction, outputs_validator: Option<OutputsValidator>, ) -> Result<H256>

Submits a new test local transaction into the transaction pool, only for testing. If the transaction is already in the pool, rebroadcast it to peers.

§Params
  • transaction - The transaction.
  • outputs_validator - Validates the transaction outputs before entering the tx-pool. (Optional, default is “passthrough”).
§Errors
§Examples

Request

{
  "id": 42,
  "jsonrpc": "2.0",
  "method": "send_test_transaction",
  "params": [
    {
      "cell_deps": [
        {
          "dep_type": "code",
          "out_point": {
            "index": "0x0",
            "tx_hash": "0xa4037a893eb48e18ed4ef61034ce26eba9c585f15c9cee102ae58505565eccc3"
          }
        }
      ],
      "header_deps": [
        "0x7978ec7ce5b507cfb52e149e36b1a23f6062ed150503c85bbf825da3599095ed"
      ],
      "inputs": [
        {
          "previous_output": {
            "index": "0x0",
            "tx_hash": "0x365698b50ca0da75dca2c87f9e7b563811d3b5813736b8cc62cc3b106faceb17"
          },
          "since": "0x0"
        }
      ],
      "outputs": [
        {
          "capacity": "0x2540be400",
          "lock": {
            "code_hash": "0x28e83a1277d48add8e72fadaa9248559e1b632bab2bd60b27955ebc4c03800a5",
            "hash_type": "data",
            "args": "0x"
          },
          "type": null
        }
      ],
      "outputs_data": [
        "0x"
      ],
      "version": "0x0",
      "witnesses": []
    },
    "passthrough"
  ]
}

Response

{
  "id": 42,
  "jsonrpc": "2.0",
  "result": "0xa0ef4eb5f4ceeb08a4c8524d84c5da95dce2f608e0ca2ec8091191b0f330c6e3"
}

Implementors§