Skip to content

Commit

Permalink
Support for send_read_only_transaction
Browse files Browse the repository at this point in the history
  • Loading branch information
aaroncox committed Jul 4, 2023
1 parent 070bfb3 commit 62b3814
Show file tree
Hide file tree
Showing 3 changed files with 126 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/api/v1/chain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,18 @@ export class ChainAPI {
})
}

async send_read_only_transaction(tx: SignedTransactionType | PackedTransaction) {
if (!isInstanceOf(tx, PackedTransaction)) {
tx = PackedTransaction.fromSigned(SignedTransaction.from(tx))
}
return this.client.call<SendTransactionResponse>({
path: '/v1/chain/send_read_only_transaction',
params: {
transaction: tx,
},
})
}

async push_transaction(tx: SignedTransactionType | PackedTransaction) {
if (!isInstanceOf(tx, PackedTransaction)) {
tx = PackedTransaction.fromSigned(SignedTransaction.from(tx))
Expand Down
42 changes: 42 additions & 0 deletions test/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,12 @@ import {
APIError,
Asset,
BlockId,
Bytes,
Checksum256,
Float64,
Name,
PrivateKey,
Serializer,
SignedTransaction,
Struct,
Transaction,
Expand Down Expand Up @@ -466,6 +468,46 @@ suite('api v1', function () {
})
})

test('chain send_read_only_transaction', async function () {
const info = await jungle4.v1.chain.get_info()
const header = info.getTransactionHeader(90)

@Struct.type('returnvalue')
class Returnvalue extends Struct {
@Struct.field(Name) message!: Name
}

const action = Action.from({
authorization: [], // No authorizations
account: 'abcabcabc333',
name: 'returnvalue',
data: Returnvalue.from({
message: 'hello',
}),
})

const transaction = Transaction.from({
...header,
actions: [action],
})

const res = await jungle4.v1.chain.send_read_only_transaction(transaction)

assert.equal(res.processed.action_traces.length, 1)
assert.equal(res.processed.action_traces[0].return_value_data, 'Validation has passed.')
assert.equal(
res.processed.action_traces[0].return_value_hex_data,
'1656616c69646174696f6e20686173207061737365642e'
)

// Test decoding raw hex data as string
const decoded = Serializer.decode({
type: 'string',
data: Bytes.from(res.processed.action_traces[0].return_value_hex_data),
})
assert.equal(decoded, 'Validation has passed.')
})

test('api errors', async function () {
try {
await jungle.call({path: '/v1/chain/get_account', params: {account_name: 'nani1'}})
Expand Down
72 changes: 72 additions & 0 deletions test/data/f5b8f07e6d21e55f8c68ee9ecdea935000a5d3ac.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
{
"headers": {
"access-control-allow-headers": "Origin, X-Requested-With, Content-Type, Accept",
"access-control-allow-methods": "GET, POST, HEAD, OPTIONS",
"access-control-allow-origin": "*",
"connection": "close",
"content-length": "1289",
"content-type": "application/json",
"date": "Tue, 04 Jul 2023 16:45:05 GMT",
"server": "nginx/1.24.0"
},
"status": 200,
"json": {
"transaction_id": "6bb877cc37abc59fa9d3ce44b9dd82f9ccd781806ec0a9c06b70cc3f5aa84113",
"processed": {
"id": "6bb877cc37abc59fa9d3ce44b9dd82f9ccd781806ec0a9c06b70cc3f5aa84113",
"block_num": 85492497,
"block_time": "2023-07-04T16:45:05.500",
"producer_block_id": null,
"receipt": {
"status": "executed",
"cpu_usage_us": 0,
"net_usage_words": 9
},
"elapsed": 69,
"net_usage": 72,
"scheduled": false,
"action_traces": [
{
"action_ordinal": 1,
"creator_action_ordinal": 0,
"closest_unnotified_ancestor_action_ordinal": 0,
"receipt": {
"receiver": "abcabcabc333",
"act_digest": "c065e5fbaadf68523d6da2ea62aa49cf876468ec441aea6c6ece2263b35ed8a9",
"global_sequence": 0,
"recv_sequence": 0,
"auth_sequence": [],
"code_sequence": 5,
"abi_sequence": 5
},
"receiver": "abcabcabc333",
"act": {
"account": "abcabcabc333",
"name": "returnvalue",
"authorization": [],
"data": {
"message": "hello"
},
"hex_data": "00000000001aa36a"
},
"context_free": false,
"elapsed": 47,
"console": "",
"trx_id": "6bb877cc37abc59fa9d3ce44b9dd82f9ccd781806ec0a9c06b70cc3f5aa84113",
"block_num": 85492497,
"block_time": "2023-07-04T16:45:05.500",
"producer_block_id": null,
"account_ram_deltas": [],
"except": null,
"error_code": null,
"return_value_hex_data": "1656616c69646174696f6e20686173207061737365642e",
"return_value_data": "Validation has passed."
}
],
"account_ram_delta": null,
"except": null,
"error_code": null
}
},
"text": "{\"transaction_id\":\"6bb877cc37abc59fa9d3ce44b9dd82f9ccd781806ec0a9c06b70cc3f5aa84113\",\"processed\":{\"id\":\"6bb877cc37abc59fa9d3ce44b9dd82f9ccd781806ec0a9c06b70cc3f5aa84113\",\"block_num\":85492497,\"block_time\":\"2023-07-04T16:45:05.500\",\"producer_block_id\":null,\"receipt\":{\"status\":\"executed\",\"cpu_usage_us\":0,\"net_usage_words\":9},\"elapsed\":69,\"net_usage\":72,\"scheduled\":false,\"action_traces\":[{\"action_ordinal\":1,\"creator_action_ordinal\":0,\"closest_unnotified_ancestor_action_ordinal\":0,\"receipt\":{\"receiver\":\"abcabcabc333\",\"act_digest\":\"c065e5fbaadf68523d6da2ea62aa49cf876468ec441aea6c6ece2263b35ed8a9\",\"global_sequence\":0,\"recv_sequence\":0,\"auth_sequence\":[],\"code_sequence\":5,\"abi_sequence\":5},\"receiver\":\"abcabcabc333\",\"act\":{\"account\":\"abcabcabc333\",\"name\":\"returnvalue\",\"authorization\":[],\"data\":{\"message\":\"hello\"},\"hex_data\":\"00000000001aa36a\"},\"context_free\":false,\"elapsed\":47,\"console\":\"\",\"trx_id\":\"6bb877cc37abc59fa9d3ce44b9dd82f9ccd781806ec0a9c06b70cc3f5aa84113\",\"block_num\":85492497,\"block_time\":\"2023-07-04T16:45:05.500\",\"producer_block_id\":null,\"account_ram_deltas\":[],\"except\":null,\"error_code\":null,\"return_value_hex_data\":\"1656616c69646174696f6e20686173207061737365642e\",\"return_value_data\":\"Validation has passed.\"}],\"account_ram_delta\":null,\"except\":null,\"error_code\":null}}"
}

0 comments on commit 62b3814

Please sign in to comment.