Skip to content

Commit

Permalink
Finished simple transaction scenario with Artillery
Browse files Browse the repository at this point in the history
  • Loading branch information
James Browning committed Feb 17, 2021
1 parent dcd76f4 commit c80ae48
Show file tree
Hide file tree
Showing 8 changed files with 237 additions and 108 deletions.
46 changes: 24 additions & 22 deletions test/performance-test/artillery/config.yaml
Original file line number Diff line number Diff line change
@@ -1,23 +1,25 @@
config:
target: "localhost:8081"
phases:
- duration: 10
arrivalCount: 10
environments:
localhost:
target: "http://localhost:8081"
phases:
- duration: 10
arrivalCount: 10
testnet:
target: "https://explorer.cardano-testnet.iohkdev.io/rosetta"
phases:
- duration: 120
arrivalRate: 10
payload:
path: "{{ $environment }}-vars.csv"
fields:
- "networkId"
- "blockIndex"
- "blockHash"
- "transactionId"
target: "localhost:8081"
phases:
- duration: 60
arrivalCount: 10
processor: "../sign-transaction.js"
environments:
localhost:
target: "http://localhost:8081"
phases:
- duration: 120
#arrivalRate: 60
arrivalCount: 180
testnet:
target: "https://explorer.cardano-testnet.iohkdev.io/rosetta"
phases:
- duration: 120
arrivalRate: 120
payload:
path: "../vars/{{ $environment }}-vars.csv"
fields:
- "networkId"
- "blockIndex"
- "blockHash"
- "transactionId"

This file was deleted.

23 changes: 19 additions & 4 deletions test/performance-test/artillery/readme.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,20 @@
### Artillery Performance Tests
```
____ ____ ____ ____ ____ ___ _ _ _ ____ ____ _ _
|__/ | | [__ |__| |__/ | | | | |___ |__/ \_/
| \ |__| ___] | | | \ | | |___ |___ |___ | \ |
```
#### Install
- `npm i artillery`

#### Configure
- Edit config.yaml and refer to https://artillery.io/docs/guides/guides/test-script-reference.html
- If targetting localhost environment then must have Testnet Rosetta instance running locally on port 8081

#### Run test
- `$(npm bin)/artillery run tests/data-block-tests.yaml --environment localhost --config config.yaml --output report`
- `$(npm bin)/artillery run tests/construction-simple-transaction.yaml --environment localhost --config config.yaml --output report`

#### Produce html report
- `$(npm bin)/artillery report report`


- npm i artillery
- $(npm bin)/artillery run data-block-tests.yaml --environment localhost --config config.yaml --output report.json
- $(npm bin)/artillery report report.json report.html
23 changes: 23 additions & 0 deletions test/performance-test/artillery/sign-transaction.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
const NaCl = require('tweetnacl');

module.exports = {
signTransaction
}

function signTransaction(context, events, done) {
const hex_bytes = context.vars['hex_bytes'];
const private_key = "41d9523b87b9bd89a4d07c9b957ae68a7472d8145d7956a692df1a8ad91957a2c117d9dd874447f47306f50a650f1e08bf4bec2cfcb2af91660f23f2db912977";
context.vars['public_key'] = "c117d9dd874447f47306f50a650f1e08bf4bec2cfcb2af91660f23f2db912977";

const key_pair = NaCl.sign.keyPair.fromSecretKey(Buffer.from(private_key, "hex"))
const secret_key = key_pair.secretKey;

context.vars['signed_hex_bytes'] = Buffer.from(
NaCl.sign.detached(
Buffer.from(hex_bytes, "hex"),
secret_key
)
).toString("hex")

return done();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,171 @@
Http-Headers: &headers
headers:
Content-Type: "application/json"

Network-Identifier: &network_identifier
network_identifier:
blockchain: "cardano"
network: "{{ networkId }}"

Public-Key: &public_key
hex_bytes: "22ae46272bffe077cecc46e1494d790d4ad453ae1c4228aa0c2e9671dcb16344"
curve_type: "edwards25519"

Ada-Currency: &ada_currency
currency:
symbol: "ADA"
decimals: 6

Operations: &operations
operations:
- operation_identifier:
index: 0
type: "input"
status: "" # maybe can be removed soon
account:
address: "{{ address }}"
amount:
value: "-100000"
<<: *ada_currency
coin_change:
coin_identifier:
identifier: "8f0e1bb31ff09a8dcc8a1b13d6ccb8f873f8d94b17bb7236c62e2d9d63d5426b:0"
coin_action: "coin_spent"
- operation_identifier:
index: 1
type: "output"
status: "" # maybe can be removed soon
account:
address: "{{ address }}"
amount:
value: 90000
<<: *ada_currency

Signatures: &signatures
signatures:
- signing_payload:
account_identifier:
address: "{{ address }}"
#metadata: ""
hex_bytes: "{{ hex_bytes }}"
signature_type: "ed25519"
public_key:
hex_bytes: "{{ public_key }}" # defined in sign-transaction.js
curve_type: "edwards25519"
signature_type: "ed25519"
hex_bytes: "{{ signed_hex_bytes }}" # produced in sign-transaction.js

scenarios:
- name: Simple Transaction
flow:
- log: "/construction/derive"
- post:
url: "/construction/derive"
capture:
json: "$.address"
as: "address"
<<: *headers
json:
<<: *network_identifier
public_key:
<<: *public_key
metadata:
relative_ttl: 1000

- log: "/construction/preprocess"
- post:
url: "/construction/preprocess"
capture:
json: "$.options"
as: "options"
<<: *headers
json:
<<: *network_identifier
<<: *operations

- log: "/construction/metadata"
- post:
url: "/construction/metadata"
capture:
- json: "$.suggested_fee"
as: "suggested_fee"
- json: "$.metadata"
as: "metadata"
<<: *headers
json:
<<: *network_identifier
options:
"{{ options }}"
public_keys:
- <<: *public_key

- log: "/construction/payloads"
- post:
url: "/construction/payloads"
capture:
- json: "$.unsigned_transaction"
as: "unsigned_transaction"
- json: "$.payloads[0].hex_bytes"
as: "hex_bytes"
<<: *headers
json:
<<: *network_identifier
<<: *operations
metadata:
"{{ metadata }}"
suggested_fee:
"{{ suggested_fee }}"

- log: "/construction/parse (unsigned)"
- post:
url: "/construction/parse"
<<: *headers
json:
<<: *network_identifier
signed: "false"
transaction:
"{{ unsigned_transaction }}"

- function: "signTransaction" # in sign-transaction.js
- log: "signed_hex_bytes: {{ signed_hex_bytes }}"

- log: "/construction/combine"
- post:
url: "/construction/combine"
capture:
json: "$.signed_transaction"
as: "signed_transaction"
<<: *headers
json:
<<: *network_identifier
unsigned_transaction: "{{ unsigned_transaction }}"
<<: *signatures

#- log: "signed_transaction={{ signed_transaction }}"
- log: "/construction/parse (signed)"
- post:
url: "/construction/parse"
<<: *headers
json:
<<: *network_identifier
signed: "true"
transaction: "{{ signed_transaction }}"
- log: "/construction/submit"
- post:
url: "/construction/submit"
<<: *headers
json:
<<: *network_identifier
signed_transaction: "{{ signed_transaction }}"

- log: "/construction/hash"
- post:
url: "/construction/hash"
capture:
json: "$.transaction_identifier.hash"
as: "hash"
<<: *headers
json:
<<: *network_identifier
signed_transaction: "{{ signed_transaction }}"
<<: *signatures

0 comments on commit c80ae48

Please sign in to comment.