Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extends agent tests to payloads+parse #5766

Merged
merged 2 commits into from
Aug 27, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions src/app/rosetta/test-agent/agent.ml
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,23 @@ let construction_api_payment_through_mempool ~logger ~rosetta_uri
[%log debug]
~metadata:[("res", Construction_metadata_response.to_yojson metadata_res)]
"Construction_metadata result $res" ;
let%bind payloads_res =
Offline.Payloads.req ~logger ~rosetta_uri ~network_response ~operations
~metadata:metadata_res.metadata
in
let%bind parse_res =
Offline.Parse.req ~logger ~rosetta_uri ~network_response
~transaction:
(`Unsigned
payloads_res.Construction_payloads_response.unsigned_transaction)
in
if not ([%equal: Operation.t list] operations parse_res.operations) then (
[%log debug]
~metadata:
[ ("expected", [%to_yojson: Operation.t list] operations)
; ("actual", [%to_yojson: Operation.t list] parse_res.operations) ]
"Construction_parse : Expected $expected, after payloads+parse $actual" ;
failwith "Operations are not equal before and after payloads+parse" ) ;
return ()

(* TODO: Break up this function in the next PR *)
Expand Down
43 changes: 43 additions & 0 deletions src/app/rosetta/test-agent/offline.ml
Original file line number Diff line number Diff line change
Expand Up @@ -47,3 +47,46 @@ module Preprocess = struct
Lift.res r ~logger ~of_yojson:Construction_preprocess_response.of_yojson
|> Lift.successfully
end

module Payloads = struct
let req ~rosetta_uri ~logger ~operations ~metadata ~network_response =
let%bind r =
post ~rosetta_uri ~logger
~body:
Construction_payloads_request.(
{ network_identifier=
List.hd_exn
network_response.Network_list_response.network_identifiers
; operations
; metadata= Some metadata }
|> to_yojson)
~path:"construction/payloads"
in
Lift.res r ~logger ~of_yojson:Construction_payloads_response.of_yojson
|> Lift.successfully
end

module Parse = struct
let req ~rosetta_uri ~logger ~transaction ~network_response =
let signed, transaction =
match transaction with
| `Unsigned txn ->
(false, txn)
| `Signed txn ->
(true, txn)
in
let%bind r =
post ~rosetta_uri ~logger
~body:
Construction_parse_request.(
{ network_identifier=
List.hd_exn
network_response.Network_list_response.network_identifiers
; transaction
; signed }
|> to_yojson)
~path:"construction/parse"
in
Lift.res r ~logger ~of_yojson:Construction_parse_response.of_yojson
|> Lift.successfully
end
2 changes: 1 addition & 1 deletion src/lib/rosetta_models/coin_change.ml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
*)

type t = {coin_identifier: Coin_identifier.t; coin_action: Enums.coinaction}
[@@deriving yojson {strict= false}, show]
[@@deriving yojson {strict= false}, show, eq]

(** CoinChange is used to represent a change in state of a some coin identified by a coin_identifier. This object is part of the Operation model and must be populated for UTXO-based blockchains. Coincidentally, this abstraction of UTXOs allows for supporting both account-based transfers and UTXO-based transfers on the same blockchain (when a transfer is account-based, don't populate this model). *)
let create (coin_identifier : Coin_identifier.t)
Expand Down
2 changes: 1 addition & 1 deletion src/lib/rosetta_models/coin_identifier.ml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
type t =
{ (* Identifier should be populated with a globally unique identifier of a Coin. In Bitcoin, this identifier would be transaction_hash:index. *)
identifier: string }
[@@deriving yojson {strict= false}, show]
[@@deriving yojson {strict= false}, show, eq]

(** CoinIdentifier uniquely identifies a Coin. *)
let create (identifier : string) : t = {identifier}
2 changes: 1 addition & 1 deletion src/lib/rosetta_models/enums.ml
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ type curvetype = (* tweedle *) string [@@deriving yojson, show]

type signaturetype = (* schnorr *) string [@@deriving yojson, show]

type coinaction = () [@@deriving yojson, show]
type coinaction = () [@@deriving yojson, show, eq]
2 changes: 1 addition & 1 deletion src/lib/rosetta_models/operation.ml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ type t =
; amount: Amount.t option [@default None]
; coin_change: Coin_change.t option [@default None]
; metadata: Yojson.Safe.t option [@default None] }
[@@deriving yojson {strict= false}, show]
[@@deriving yojson {strict= false}, show, eq]

(** Operations contain all balance-changing information within a transaction. They are always one-sided (only affect 1 AccountIdentifier) and can succeed or fail independently from a Transaction. *)
let create (operation_identifier : Operation_identifier.t) (_type : string)
Expand Down
2 changes: 1 addition & 1 deletion src/lib/rosetta_models/operation_identifier.ml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ type t =
index: int64
; (* Some blockchains specify an operation index that is essential for client use. For example, Bitcoin uses a network_index to identify which UTXO was used in a transaction. network_index should not be populated if there is no notion of an operation index in a blockchain (typically most account-based blockchains). *)
network_index: int64 option [@default None] }
[@@deriving yojson {strict= false}, show]
[@@deriving yojson {strict= false}, show, eq]

(** The operation_identifier uniquely identifies an operation within a transaction. *)
let create (index : int64) : t = {index; network_index= None}