diff --git a/rpc/client.go b/rpc/client.go index 7bce881..3a873dd 100644 --- a/rpc/client.go +++ b/rpc/client.go @@ -51,6 +51,8 @@ type ClientInformational interface { GetAccountBalance(ctx context.Context, stateRootHash *string, purseURef string) (StateGetBalanceResult, error) // GetDeploy retrieves a Deploy from a network. It requires a deploy_hash to query the Deploy. GetDeploy(ctx context.Context, hash string) (InfoGetDeployResult, error) + // GetDeployFinalizedApproval returns Deploy with the finalized approvals substituted. + GetDeployFinalizedApproval(ctx context.Context, hash string) (InfoGetDeployResult, error) // GetDictionaryItem returns an item from a Dictionary. // Every dictionary has a seed URef, findable by using a dictionary_identifier. // The address of a stored value is the blake2b hash of the seed URef and the byte representation of the dictionary key. @@ -63,6 +65,8 @@ type ClientInformational interface { // QueryGlobalStateByBlockHash allows for you to query for a value stored under certain keys in global state. QueryGlobalStateByBlockHash(ctx context.Context, blockHash, key string, path []string) (QueryGlobalStateResult, error) + // QueryGlobalStateByBlockHeight allows for you to query for a value stored under certain keys in global state. + QueryGlobalStateByBlockHeight(ctx context.Context, blockHeight uint64, key string, path []string) (QueryGlobalStateResult, error) // QueryGlobalStateByStateHash allows for you to query for a value stored under certain keys in global state. // If the param stateRootHash is nil, the client will make an additional RPC call to retrieve the latest stateRootHash. QueryGlobalStateByStateHash(ctx context.Context, stateRootHash *string, key string, path []string) (QueryGlobalStateResult, error) @@ -108,6 +112,10 @@ type ClientInformational interface { // GetPeers return a list of peers connected to the node on a Casper network. // The responses return information specific to the queried node, and as such, will vary. GetPeers(ctx context.Context) (InfoGetPeerResult, error) + // QueryBalance queries for balances under a given PurseIdentifier + QueryBalance(ctx context.Context, identifier PurseIdentifier) (QueryBalanceResult, error) + // GetChainspec returns the raw bytes of the chainspec.toml, accounts.toml and global_state.toml files as read at node startup. + GetChainspec(ctx context.Context) (InfoGetChainspecResult, error) } // ClientTransactional contains the description of account_put_deploy, diff --git a/rpc/error.go b/rpc/error.go index b3ebec6..2852d91 100644 --- a/rpc/error.go +++ b/rpc/error.go @@ -8,10 +8,11 @@ import ( type RpcError struct { Code int `json:"code"` Message string `json:"message"` + Data string `json:"data,omitempty"` } func (h *RpcError) Error() string { - return h.Message + return fmt.Sprintf("key: %s, data: %s", h.Message, h.Data) } type HttpError struct { diff --git a/rpc/request.go b/rpc/request.go index 3768b88..724812c 100644 --- a/rpc/request.go +++ b/rpc/request.go @@ -45,6 +45,9 @@ const ( MethodGetStatus Method = "info_get_status" MethodGetPeers Method = "info_get_peers" MethodPutDeploy Method = "account_put_deploy" + MethodSpeculativeExec Method = "speculative_exec" + MethodQueryBalance Method = "query_balance" + MethodInfoGetChainspec Method = "info_get_chainspec" ) // RpcRequest is a wrapper struct for an RPC call method that can be serialized to JSON. @@ -81,6 +84,7 @@ type ParamQueryGlobalState struct { type ParamQueryGlobalStateID struct { StateRootHash string `json:"StateRootHash,omitempty"` BlockHash string `json:"BlockHash,omitempty"` + BlockHeight uint64 `json:"BlockHeight,omitempty"` } func NewQueryGlobalStateParam(key string, path []string, id ParamQueryGlobalStateID) ParamQueryGlobalState { @@ -124,3 +128,18 @@ func NewParamStateDictionaryItem(stateRootHash, uref, key string) map[string]int }, } } + +type SpeculativeExecParams struct { + Deploy types.Deploy `json:"deploy"` + BlockIdentifier *BlockIdentifier `json:"block_identifier,omitempty"` +} + +type PurseIdentifier struct { + MainPurseUnderPublicKey *keypair.PublicKey `json:"main_purse_under_public_key,omitempty"` + MainPurseUnderAccountHash *string `json:"main_purse_under_account_hash,omitempty"` + PurseUref *string `json:"purse_uref,omitempty"` +} + +type QueryBalanceRequest struct { + PurseIdentifier PurseIdentifier `json:"purse_identifier"` +} diff --git a/rpc/response.go b/rpc/response.go index 5f473c3..99d32cd 100644 --- a/rpc/response.go +++ b/rpc/response.go @@ -2,9 +2,9 @@ package rpc import ( "encoding/json" - "time" "github.com/make-software/casper-go-sdk/types" + "github.com/make-software/casper-go-sdk/types/clvalue" "github.com/make-software/casper-go-sdk/types/key" "github.com/make-software/casper-go-sdk/types/keypair" ) @@ -53,6 +53,8 @@ type InfoGetDeployResult struct { ApiVersion string `json:"api_version"` Deploy types.Deploy `json:"deploy"` ExecutionResults []types.DeployExecutionResult `json:"execution_results"` + BlockHash *key.Hash `json:"block_hash,omitempty"` + BlockHeight *uint64 `json:"block_height,omitempty"` } type ChainGetEraInfoResult struct { @@ -147,23 +149,51 @@ type InfoGetStatusResult struct { StartingStateRootHash string `json:"starting_state_root_hash"` // Time that passed since the node has started. format "2months 20days 22h 3m 21s 512ms" Uptime string `json:"uptime"` + // Indicating the node's current operating mode + ReactorState string `json:"reactor_state"` + // Indicating the time the node last made progress + LastProgress types.Timestamp `json:"last_progress"` + // Indicating the highest contiguous sequence of the block chain for which the node has complete data + AvailableBlockRange struct { + Low uint64 `json:"low"` + High uint64 `json:"high"` + } `json:"available_block_range"` + // Indicating the state of the block synchronizer component + BlockSync struct { + Historical string `json:"historical,omitempty"` + Forward string `json:"forward,omitempty"` + } `json:"block_sync"` } // NodeNextUpgrade contains the information about the next protocol upgrade. type NodeNextUpgrade struct { //The first era to which the associated protocol version applies. - ActivationPoint ActivationPoint `json:"activation_point"` + ActivationPoint uint64 `json:"activation_point"` // The protocol version of the next upgrade ProtocolVersion string `json:"protocol_version"` } -// ActivationPoint is the first era to which the associated protocol version applies. -type ActivationPoint struct { - EraID uint32 `json:"era_id"` - Timestamp time.Time `json:"timestamp"` -} - type PutDeployResult struct { ApiVersion string `json:"api_version"` DeployHash key.Hash `json:"deploy_hash"` } + +type SpeculativeExecResult struct { + ApiVersion string `json:"api_version"` + DeployHash key.Hash `json:"deploy_hash"` + ExecutionResult types.ExecutionResultStatus `json:"execution_result"` +} + +type QueryBalanceResult struct { + ApiVersion string `json:"api_version"` + Balance clvalue.UInt512 `json:"balance"` +} + +type InfoGetChainspecResult struct { + ApiVersion string `json:"api_version"` + ChainspecBytes struct { + ChainspecBytes string `json:"chainspec_bytes,omitempty"` + MaybeGenesisAccountsBytes string `json:"maybe_genesis_accounts_bytes,omitempty"` + MaybeGlobalStateBytes string `json:"maybe_global_state_bytes,omitempty"` + } `json:"chainspec_bytes"` +} diff --git a/rpc/rpc_client.go b/rpc/rpc_client.go index 37ce47e..1273631 100644 --- a/rpc/rpc_client.go +++ b/rpc/rpc_client.go @@ -33,6 +33,14 @@ func (c *client) GetDeploy(ctx context.Context, hash string) (InfoGetDeployResul }, &result) } +func (c *client) GetDeployFinalizedApproval(ctx context.Context, hash string) (InfoGetDeployResult, error) { + var result InfoGetDeployResult + return result, c.processRequest(ctx, MethodGetDeploy, map[string]interface{}{ + "deploy_hash": hash, + "finalized_approvals": true, + }, &result) +} + func (c *client) GetStateItem(ctx context.Context, stateRootHash *string, key string, path []string) (StateGetItemResult, error) { if stateRootHash == nil { latestHashResult, err := c.GetStateRootHashLatest(ctx) @@ -57,6 +65,13 @@ func (c *client) QueryGlobalStateByBlockHash(ctx context.Context, blockHash, key }), &result) } +func (c *client) QueryGlobalStateByBlockHeight(ctx context.Context, blockHeight uint64, key string, path []string) (QueryGlobalStateResult, error) { + var result QueryGlobalStateResult + return result, c.processRequest(ctx, MethodQueryGlobalState, NewQueryGlobalStateParam(key, path, ParamQueryGlobalStateID{ + BlockHeight: blockHeight, + }), &result) +} + func (c *client) QueryGlobalStateByStateHash(ctx context.Context, stateRootHash *string, key string, path []string) (QueryGlobalStateResult, error) { if stateRootHash == nil { latestHashResult, err := c.GetStateRootHashLatest(ctx) @@ -221,6 +236,16 @@ func (c *client) PutDeploy(ctx context.Context, deploy types.Deploy) (PutDeployR return result, c.processRequest(ctx, MethodPutDeploy, PutDeployRequest{Deploy: deploy}, &result) } +func (c *client) QueryBalance(ctx context.Context, identifier PurseIdentifier) (QueryBalanceResult, error) { + var result QueryBalanceResult + return result, c.processRequest(ctx, MethodQueryBalance, QueryBalanceRequest{identifier}, &result) +} + +func (c *client) GetChainspec(ctx context.Context) (InfoGetChainspecResult, error) { + var result InfoGetChainspecResult + return result, c.processRequest(ctx, MethodInfoGetChainspec, nil, &result) +} + func (c *client) processRequest(ctx context.Context, method Method, params interface{}, result any) error { request := DefaultRpcRequest(method, params) if reqID := GetReqIdCtx(ctx); reqID != "0" { diff --git a/rpc/speculative_client.go b/rpc/speculative_client.go new file mode 100644 index 0000000..25f9e22 --- /dev/null +++ b/rpc/speculative_client.go @@ -0,0 +1,43 @@ +package rpc + +import ( + "context" + "encoding/json" + "fmt" + + "github.com/make-software/casper-go-sdk/types" +) + +type SpeculativeClient struct { + handler Handler +} + +func NewSpeculativeClient(handler Handler) *SpeculativeClient { + return &SpeculativeClient{handler: handler} +} + +func (c SpeculativeClient) SpeculativeExec(ctx context.Context, deploy types.Deploy, identifier *BlockIdentifier) (SpeculativeExecResult, error) { + var result SpeculativeExecResult + request := DefaultRpcRequest(MethodSpeculativeExec, SpeculativeExecParams{ + Deploy: deploy, + BlockIdentifier: identifier, + }) + if reqID := GetReqIdCtx(ctx); reqID != "0" { + request.ID = reqID + } + resp, err := c.handler.ProcessCall(ctx, request) + if err != nil { + return SpeculativeExecResult{}, err + } + + if resp.Error != nil { + return SpeculativeExecResult{}, fmt.Errorf("rpc call failed, details: %w", resp.Error) + } + + err = json.Unmarshal(resp.Result, &result) + if err != nil { + return SpeculativeExecResult{}, fmt.Errorf("%w, details: %s", ErrResultUnmarshal, err.Error()) + } + + return result, nil +} diff --git a/tests/data/block/block_switch_system_proposer.json b/tests/data/block/block_switch_system_proposer.json new file mode 100644 index 0000000..aabd311 --- /dev/null +++ b/tests/data/block/block_switch_system_proposer.json @@ -0,0 +1,82 @@ +{ + "hash": "b287dd3ae44e57e944bf357d50f8c09fa6a58cb3cdccebb94febf2733d243d92", + "header": { + "parent_hash": "3702837e19058988f12260689dc6cf6adf3f31d06d4b34109a4a4fda44c23e08", + "state_root_hash": "05294c6b79095e72c24544852b1d678350554e16bbd430adab4dd0b5be0bccfe", + "body_hash": "5187b7a8021bf4f2c004ea3a54cfece1754f11c7624d2363c7f4cf4fddd1441e", + "random_bit": false, + "accumulated_seed": "abd4677d96e41ffc598761b58e93ebd5ab91affcc1b7d09e4b3bc63044fcced0", + "era_end": { + "era_report": { + "equivocators": [], + "rewards": [], + "inactive_validators": [] + }, + "next_era_validator_weights": [ + { + "validator": "0115c9b40c06ff99b0cbadf1140b061b5dbf92103e66a6330fbcc7768f5219c1ce", + "weight": "295643652543863089" + }, + { + "validator": "011b19ef983c039a2a335f2f35199bf8cad5ba2c583bd709748feb76f24ffb1bab", + "weight": "294564238999375236" + }, + { + "validator": "011d86fcc3e438fcb47d4d9af77e9db97ca1c322c3e87d5a4ea6f3386b9ddcd6ed", + "weight": "294159738231573499" + }, + { + "validator": "017234b285929170324e1051ccd887dc08adf049650ecf5d383985b0b0048ab39b", + "weight": "284471020019645189" + }, + { + "validator": "017fec504c642f2b321b8591f1c3008348c57a81acafceb5a392cf8416a5fb4a3c", + "weight": "294691173297447085" + }, + { + "validator": "019e7b8bdec03ba83be4f5443d9f7f9111c77fec984ce9bb5bb7eb3da1e689c02d", + "weight": "294679465132340585" + }, + { + "validator": "01cb8e121682e087058610828a6f75e8ca504321508243c7518a4047d3284f2f3c", + "weight": "292948235437478173" + } + ] + }, + "timestamp": "2023-05-11T18:24:49.664Z", + "era_id": 9128, + "height": 1749608, + "protocol_version": "1.5.0" + }, + "body": { + "proposer": "00", + "deploy_hashes": [], + "transfer_hashes": [] + }, + "proofs": [ + { + "public_key": "011b19ef983c039a2a335f2f35199bf8cad5ba2c583bd709748feb76f24ffb1bab", + "signature": "01f6bfd939b7797f1be4f16e597a115f38687745ad32dcd3402ef38c750b6abfb50c0918cb1e57ea25b174fa632a1f62000cc727aff703eb17c3b5f976ca17f304" + }, + { + "public_key": "011d86fcc3e438fcb47d4d9af77e9db97ca1c322c3e87d5a4ea6f3386b9ddcd6ed", + "signature": "019a011ea3f5d5d5446748ae58c40f5d6f0f255dfd1a75161d84b2c280f79a523756fee665401617e765651c32dd4a10598a15e71ae08ee3b48479033db4d2f30c" + }, + { + "public_key": "017234b285929170324e1051ccd887dc08adf049650ecf5d383985b0b0048ab39b", + "signature": "017664b8c0b2cdba2261ae1af6f213ad0f8812799e2fbd840b668799221c4f0a5951aa7f9e1828bbbe16fc51e1e94e5c1a935f31c3781feef7a36500c660774601" + }, + { + "public_key": "017fec504c642f2b321b8591f1c3008348c57a81acafceb5a392cf8416a5fb4a3c", + "signature": "01e921e323ce23a1e7cf9453e0efdc23c0ee9001d28eb8124da73e85f0fc5fe3f6cd22008aa7053cf5c8c20813230f414238b95032f98c0ce6e09e643dfc011009" + }, + { + "public_key": "019e7b8bdec03ba83be4f5443d9f7f9111c77fec984ce9bb5bb7eb3da1e689c02d", + "signature": "01fcdf5f457fbe2868e03a15bee5af2c15fa4d8fce05888fde0c7b080ffda418511c380a71c500097ff840e0e68ff0976e4c0ec74fd318554e8557a4d5b6042c06" + }, + { + "public_key": "01cb8e121682e087058610828a6f75e8ca504321508243c7518a4047d3284f2f3c", + "signature": "014bee8a716df01a593a535ebf2dee20da400a99dffe1d56e07f2dfa5f947d4d5003e4ee51289e389998e4c9b45efe00a1193d7db79a67dd824d489ddf16ad820e" + } + ] +} diff --git a/tests/data/contract/contract_package_example.json b/tests/data/contract/contract_package_example.json index 2a3b234..efab38b 100644 --- a/tests/data/contract/contract_package_example.json +++ b/tests/data/contract/contract_package_example.json @@ -19,5 +19,6 @@ "group": "constructor", "keys": [] } - ] + ], + "lock_status": "Unlocked" } \ No newline at end of file diff --git a/tests/data/deploy/deploy_with_transfer.json b/tests/data/deploy/deploy_with_transfer.json new file mode 100644 index 0000000..4ab93ee --- /dev/null +++ b/tests/data/deploy/deploy_with_transfer.json @@ -0,0 +1,65 @@ +{ + "hash": "ccb36e4cbf6fa1c19406d571e36862060d35af708dab89ad6d9b937556f25c2c", + "header": { + "account": "0115394d1f395a87dfed4ab62bbfbc91b573bbb2bffb2c8ebb9c240c51d95bcc4d", + "timestamp": "2023-07-12T14:59:40.406Z", + "ttl": "30m", + "gas_price": 1, + "body_hash": "568593b2b7860ff60d085b80fd7c1666a8ac43b41ad15296fda594e0aabae0f0", + "dependencies": [], + "chain_name": "casper-net-1" + }, + "payment": { + "ModuleBytes": { + "module_bytes": "", + "args": [ + [ + "amount", + { + "cl_type": "U512", + "bytes": "0440787d01", + "parsed": "25000000" + } + ] + ] + } + }, + "session": { + "Transfer": { + "args": [ + [ + "amount", + { + "cl_type": "U512", + "bytes": "0400f90295", + "parsed": "2500000000" + } + ], + [ + "target", + { + "cl_type": "PublicKey", + "bytes": "01bf65587c501685ca5d0cb5293509fa4cecdb4503c7364084e18e14339e46a46f", + "parsed": "01bf65587c501685ca5d0cb5293509fa4cecdb4503c7364084e18e14339e46a46f" + } + ], + [ + "id", + { + "cl_type": { + "Option": "U64" + }, + "bytes": "010100000000000000", + "parsed": 1 + } + ] + ] + } + }, + "approvals": [ + { + "signer": "0115394d1f395a87dfed4ab62bbfbc91b573bbb2bffb2c8ebb9c240c51d95bcc4d", + "signature": "01299f8c15f04c14cf68706b8d34f520826113cb776826628661d4c796ddcf1b4ee36b9bcd0b597800ac0501cb26cfa54abf8c0e4eaf7b498d5c283c8f1caacb0e" + } + ] +} \ No newline at end of file diff --git a/tests/data/keys/docker-nctl-secret.pem b/tests/data/keys/docker-nctl-secret.pem new file mode 100644 index 0000000..f6a41bd --- /dev/null +++ b/tests/data/keys/docker-nctl-secret.pem @@ -0,0 +1,3 @@ +-----BEGIN PRIVATE KEY----- +MC4CAQAwBQYDK2VwBCIEIBUARqE05TYBPqqYe4Yi6YXBsYOuLA3lhFSquB21JY5q +-----END PRIVATE KEY----- diff --git a/tests/data/rpc_response/get_chainspec.json b/tests/data/rpc_response/get_chainspec.json new file mode 100644 index 0000000..10a22a5 --- /dev/null +++ b/tests/data/rpc_response/get_chainspec.json @@ -0,0 +1,12 @@ +{ + "jsonrpc": "2.0", + "id": "122", + "result": { + "api_version": "1.0.0", + "chainspec_bytes": { + "chainspec_bytes": "5b70726f746f636f6c5d0a76657273696f6e203d2022312e302e30220a686172645f7265736574203d2066616c73650a61637469766174696f6e5f706f696e74203d2022323032332d30372d31325431323a33313a35392e3435373536375a220a0a5b6e6574776f726b5d0a6e616d65203d20226361737065722d6e65742d31220a6d6178696d756d5f6e65745f6d6573736167655f73697a65203d2032353136353832340a0a5b636f72655d0a6572615f6475726174696f6e203d202234317365636f6e6473220a6d696e696d756d5f6572615f686569676874203d20350a6d696e696d756d5f626c6f636b5f74696d65203d2022343039366d73220a76616c696461746f725f736c6f7473203d2031300a66696e616c6974795f7468726573686f6c645f6672616374696f6e203d205b20312c20332c5d0a73746172745f70726f746f636f6c5f76657273696f6e5f776974685f7374726963745f66696e616c6974795f7369676e6174757265735f7265717569726564203d2022312e352e30220a6c65676163795f72657175697265645f66696e616c697479203d2022537472696374220a61756374696f6e5f64656c6179203d20310a6c6f636b65645f66756e64735f706572696f64203d2022393064617973220a76657374696e675f7363686564756c655f706572696f64203d20223133207765656b73220a756e626f6e64696e675f64656c6179203d20370a726f756e645f736569676e696f726167655f72617465203d205b20312c20343230303030303030303030303030303030302c5d0a6d61785f6173736f6369617465645f6b657973203d203130300a6d61785f72756e74696d655f63616c6c5f737461636b5f686569676874203d2031320a6d696e696d756d5f64656c65676174696f6e5f616d6f756e74203d203530303030303030303030300a7072756e655f62617463685f73697a65203d20300a7374726963745f617267756d656e745f636865636b696e67203d2066616c73650a73696d756c74616e656f75735f706565725f7265717565737473203d20350a636f6e73656e7375735f70726f746f636f6c203d202248696768776179220a6d61785f64656c656761746f72735f7065725f76616c696461746f72203d20300a0a5b686967687761795d0a6d6178696d756d5f726f756e645f6c656e677468203d20223532357365636f6e6473220a726564756365645f7265776172645f6d756c7469706c696572203d205b20312c20352c5d0a0a5b6465706c6f79735d0a6d61785f7061796d656e745f636f7374203d202230220a6d61785f74746c203d20223138686f757273220a6d61785f646570656e64656e63696573203d2031300a6d61785f626c6f636b5f73697a65203d2031303438353736300a6d61785f6465706c6f795f73697a65203d20313034383537360a626c6f636b5f6d61785f6465706c6f795f636f756e74203d203130300a626c6f636b5f6d61785f7472616e736665725f636f756e74203d20313030300a626c6f636b5f6d61785f617070726f76616c5f636f756e74203d20323630300a626c6f636b5f6761735f6c696d6974203d2031303030303030303030303030300a7061796d656e745f617267735f6d61785f6c656e677468203d20313032340a73657373696f6e5f617267735f6d61785f6c656e677468203d20313032340a6e61746976655f7472616e736665725f6d696e696d756d5f6d6f746573203d20323530303030303030300a0a5b7761736d5d0a6d61785f6d656d6f7279203d2036340a6d61785f737461636b5f686569676874203d203530300a0a5b73797374656d5f636f7374735d0a7761736d6c6573735f7472616e736665725f636f7374203d203130303030303030300a0a5b7761736d2e73746f726167655f636f7374735d0a6761735f7065725f62797465203d203633303030300a0a5b7761736d2e6f70636f64655f636f7374735d0a626974203d203330300a616464203d203231300a6d756c203d203234300a646976203d203332300a6c6f6164203d20323530300a73746f7265203d20343730300a636f6e7374203d203131300a6c6f63616c203d203339300a676c6f62616c203d203339300a696e74656765725f636f6d70617269736f6e203d203235300a636f6e76657273696f6e203d203432300a756e726561636861626c65203d203237300a6e6f70203d203230300a63757272656e745f6d656d6f7279203d203239300a67726f775f6d656d6f7279203d203234303030300a0a5b73797374656d5f636f7374732e61756374696f6e5f636f7374735d0a6765745f6572615f76616c696461746f7273203d2031303030300a726561645f736569676e696f726167655f726563697069656e7473203d2031303030300a6164645f626964203d20323530303030303030300a77697468647261775f626964203d20323530303030303030300a64656c6567617465203d20323530303030303030300a756e64656c6567617465203d20323530303030303030300a72756e5f61756374696f6e203d2031303030300a736c617368203d2031303030300a64697374726962757465203d2031303030300a77697468647261775f64656c656761746f725f726577617264203d2031303030300a77697468647261775f76616c696461746f725f726577617264203d2031303030300a726561645f6572615f6964203d2031303030300a61637469766174655f626964203d2031303030300a726564656c6567617465203d20323530303030303030300a0a5b73797374656d5f636f7374732e6d696e745f636f7374735d0a6d696e74203d20323530303030303030300a7265647563655f746f74616c5f737570706c79203d2031303030300a637265617465203d20323530303030303030300a62616c616e6365203d2031303030300a7472616e73666572203d2031303030300a726561645f626173655f726f756e645f726577617264203d2031303030300a6d696e745f696e746f5f6578697374696e675f7075727365203d20323530303030303030300a0a5b73797374656d5f636f7374732e68616e646c655f7061796d656e745f636f7374735d0a6765745f7061796d656e745f7075727365203d2031303030300a7365745f726566756e645f7075727365203d2031303030300a6765745f726566756e645f7075727365203d2031303030300a66696e616c697a655f7061796d656e74203d2031303030300a0a5b73797374656d5f636f7374732e7374616e646172645f7061796d656e745f636f7374735d0a706179203d2031303030300a0a5b7761736d2e6f70636f64655f636f7374732e636f6e74726f6c5f666c6f775d0a626c6f636b203d203434300a6c6f6f70203d203434300a6966203d203434300a656c7365203d203434300a656e64203d203434300a6272203d203434303030300a62725f6966203d203434303030300a72657475726e203d203434300a73656c656374203d203434300a63616c6c203d203134303030300a63616c6c5f696e646972656374203d203134303030300a64726f70203d203434300a0a5b7761736d2e686f73745f66756e6374696f6e5f636f7374732e6164645d0a636f7374203d20353830300a617267756d656e7473203d205b20302c20302c20302c20302c5d0a0a5b7761736d2e686f73745f66756e6374696f6e5f636f7374732e6164645f6173736f6369617465645f6b65795d0a636f7374203d20393030300a617267756d656e7473203d205b20302c20302c20302c5d0a0a5b7761736d2e686f73745f66756e6374696f6e5f636f7374732e6164645f636f6e74726163745f76657273696f6e5d0a636f7374203d203230300a617267756d656e7473203d205b20302c20302c20302c20302c20302c20302c20302c20302c20302c20302c5d0a0a5b7761736d2e686f73745f66756e6374696f6e5f636f7374732e626c616b6532625d0a636f7374203d203230300a617267756d656e7473203d205b20302c20302c20302c20302c5d0a0a5b7761736d2e686f73745f66756e6374696f6e5f636f7374732e63616c6c5f636f6e74726163745d0a636f7374203d20343530300a617267756d656e7473203d205b20302c20302c20302c20302c20302c203432302c20302c5d0a0a5b7761736d2e686f73745f66756e6374696f6e5f636f7374732e63616c6c5f76657273696f6e65645f636f6e74726163745d0a636f7374203d20343530300a617267756d656e7473203d205b20302c20302c20302c20302c20302c20302c20302c203432302c20302c5d0a0a5b7761736d2e686f73745f66756e6374696f6e5f636f7374732e6372656174655f636f6e74726163745f7061636b6167655f61745f686173685d0a636f7374203d203230300a617267756d656e7473203d205b20302c20302c5d0a0a5b7761736d2e686f73745f66756e6374696f6e5f636f7374732e6372656174655f636f6e74726163745f757365725f67726f75705d0a636f7374203d203230300a617267756d656e7473203d205b20302c20302c20302c20302c20302c20302c20302c20302c5d0a0a5b7761736d2e686f73745f66756e6374696f6e5f636f7374732e6372656174655f70757273655d0a636f7374203d20323530303030303030300a617267756d656e7473203d205b20302c20302c5d0a0a5b7761736d2e686f73745f66756e6374696f6e5f636f7374732e64697361626c655f636f6e74726163745f76657273696f6e5d0a636f7374203d203230300a617267756d656e7473203d205b20302c20302c20302c20302c5d0a0a5b7761736d2e686f73745f66756e6374696f6e5f636f7374732e6765745f62616c616e63655d0a636f7374203d20333830300a617267756d656e7473203d205b20302c20302c20302c5d0a0a5b7761736d2e686f73745f66756e6374696f6e5f636f7374732e6765745f626c6f636b74696d655d0a636f7374203d203333300a617267756d656e7473203d205b20302c5d0a0a5b7761736d2e686f73745f66756e6374696f6e5f636f7374732e6765745f63616c6c65725d0a636f7374203d203338300a617267756d656e7473203d205b20302c5d0a0a5b7761736d2e686f73745f66756e6374696f6e5f636f7374732e6765745f6b65795d0a636f7374203d20323030300a617267756d656e7473203d205b20302c203434302c20302c20302c20302c5d0a0a5b7761736d2e686f73745f66756e6374696f6e5f636f7374732e6765745f6d61696e5f70757273655d0a636f7374203d20313330300a617267756d656e7473203d205b20302c5d0a0a5b7761736d2e686f73745f66756e6374696f6e5f636f7374732e6765745f6e616d65645f6172675d0a636f7374203d203230300a617267756d656e7473203d205b20302c20302c20302c20302c5d0a0a5b7761736d2e686f73745f66756e6374696f6e5f636f7374732e6765745f6e616d65645f6172675f73697a655d0a636f7374203d203230300a617267756d656e7473203d205b20302c20302c20302c5d0a0a5b7761736d2e686f73745f66756e6374696f6e5f636f7374732e6765745f70686173655d0a636f7374203d203731300a617267756d656e7473203d205b20302c5d0a0a5b7761736d2e686f73745f66756e6374696f6e5f636f7374732e6765745f73797374656d5f636f6e74726163745d0a636f7374203d20313130300a617267756d656e7473203d205b20302c20302c20302c5d0a0a5b7761736d2e686f73745f66756e6374696f6e5f636f7374732e6861735f6b65795d0a636f7374203d20313530300a617267756d656e7473203d205b20302c203834302c5d0a0a5b7761736d2e686f73745f66756e6374696f6e5f636f7374732e69735f76616c69645f757265665d0a636f7374203d203736300a617267756d656e7473203d205b20302c20302c5d0a0a5b7761736d2e686f73745f66756e6374696f6e5f636f7374732e6c6f61645f6e616d65645f6b6579735d0a636f7374203d2034323030300a617267756d656e7473203d205b20302c20302c5d0a0a5b7761736d2e686f73745f66756e6374696f6e5f636f7374732e6e65775f757265665d0a636f7374203d2031373030300a617267756d656e7473203d205b20302c20302c203539302c5d0a0a5b7761736d2e686f73745f66756e6374696f6e5f636f7374732e72616e646f6d5f62797465735d0a636f7374203d203230300a617267756d656e7473203d205b20302c20302c5d0a0a5b7761736d2e686f73745f66756e6374696f6e5f636f7374732e7072696e745d0a636f7374203d2032303030300a617267756d656e7473203d205b20302c20343630302c5d0a0a5b7761736d2e686f73745f66756e6374696f6e5f636f7374732e70726f766973696f6e5f636f6e74726163745f757365725f67726f75705f757265665d0a636f7374203d203230300a617267756d656e7473203d205b20302c20302c20302c20302c20302c5d0a0a5b7761736d2e686f73745f66756e6374696f6e5f636f7374732e7075745f6b65795d0a636f7374203d2033383030300a617267756d656e7473203d205b20302c20313130302c20302c20302c5d0a0a5b7761736d2e686f73745f66756e6374696f6e5f636f7374732e726561645f686f73745f6275666665725d0a636f7374203d20333530300a617267756d656e7473203d205b20302c203331302c20302c5d0a0a5b7761736d2e686f73745f66756e6374696f6e5f636f7374732e726561645f76616c75655d0a636f7374203d20363030300a617267756d656e7473203d205b20302c20302c20302c5d0a0a5b7761736d2e686f73745f66756e6374696f6e5f636f7374732e726561645f76616c75655f6c6f63616c5d0a636f7374203d20353530300a617267756d656e7473203d205b20302c203539302c20302c5d0a0a5b7761736d2e686f73745f66756e6374696f6e5f636f7374732e72656d6f76655f6173736f6369617465645f6b65795d0a636f7374203d20343230300a617267756d656e7473203d205b20302c20302c5d0a0a5b7761736d2e686f73745f66756e6374696f6e5f636f7374732e72656d6f76655f636f6e74726163745f757365725f67726f75705d0a636f7374203d203230300a617267756d656e7473203d205b20302c20302c20302c20302c5d0a0a5b7761736d2e686f73745f66756e6374696f6e5f636f7374732e72656d6f76655f636f6e74726163745f757365725f67726f75705f75726566735d0a636f7374203d203230300a617267756d656e7473203d205b20302c20302c20302c20302c20302c20302c5d0a0a5b7761736d2e686f73745f66756e6374696f6e5f636f7374732e72656d6f76655f6b65795d0a636f7374203d2036313030300a617267756d656e7473203d205b20302c20333230302c5d0a0a5b7761736d2e686f73745f66756e6374696f6e5f636f7374732e7265745d0a636f7374203d2032333030300a617267756d656e7473203d205b20302c203432303030302c5d0a0a5b7761736d2e686f73745f66756e6374696f6e5f636f7374732e7265766572745d0a636f7374203d203530300a617267756d656e7473203d205b20302c5d0a0a5b7761736d2e686f73745f66756e6374696f6e5f636f7374732e7365745f616374696f6e5f7468726573686f6c645d0a636f7374203d2037343030300a617267756d656e7473203d205b20302c20302c5d0a0a5b7761736d2e686f73745f66756e6374696f6e5f636f7374732e7472616e736665725f66726f6d5f70757273655f746f5f6163636f756e745d0a636f7374203d20323530303030303030300a617267756d656e7473203d205b20302c20302c20302c20302c20302c20302c20302c20302c20302c5d0a0a5b7761736d2e686f73745f66756e6374696f6e5f636f7374732e7472616e736665725f66726f6d5f70757273655f746f5f70757273655d0a636f7374203d2038323030300a617267756d656e7473203d205b20302c20302c20302c20302c20302c20302c20302c20302c5d0a0a5b7761736d2e686f73745f66756e6374696f6e5f636f7374732e7472616e736665725f746f5f6163636f756e745d0a636f7374203d20323530303030303030300a617267756d656e7473203d205b20302c20302c20302c20302c20302c20302c20302c5d0a0a5b7761736d2e686f73745f66756e6374696f6e5f636f7374732e7570646174655f6173736f6369617465645f6b65795d0a636f7374203d20343230300a617267756d656e7473203d205b20302c20302c20302c5d0a0a5b7761736d2e686f73745f66756e6374696f6e5f636f7374732e77726974655d0a636f7374203d2031343030300a617267756d656e7473203d205b20302c20302c20302c203938302c5d0a0a5b7761736d2e686f73745f66756e6374696f6e5f636f7374732e77726974655f6c6f63616c5d0a636f7374203d20393530300a617267756d656e7473203d205b20302c20313830302c20302c203532302c5d0a0a5b7761736d2e6f70636f64655f636f7374732e636f6e74726f6c5f666c6f772e62725f7461626c655d0a636f7374203d203434303030300a73697a655f6d756c7469706c696572203d203130300a", + "maybe_genesis_accounts_bytes": "23204641554345542e0a5b5b6163636f756e74735d5d0a7075626c69635f6b6579203d2022303166313764306331313463303933623166363462663166386463373461366565326232363938346538363637366461363732646334313932323831363265613935220a62616c616e6365203d202231303030303030303030303030303030303030303030303030303030303030303030220a0a232056414c494441544f5220312e0a5b5b6163636f756e74735d5d0a7075626c69635f6b6579203d2022303131353339346431663339356138376466656434616236326262666263393162353733626262326266666232633865626239633234306335316439356263633464220a62616c616e6365203d202231303030303030303030303030303030303030303030303030303030303030303030220a0a5b6163636f756e74732e76616c696461746f725d0a626f6e6465645f616d6f756e74203d202231303030303030303030303030303030303031220a64656c65676174696f6e5f72617465203d20310a0a232056414c494441544f5220322e0a5b5b6163636f756e74735d5d0a7075626c69635f6b6579203d2022303137393134653637303332616662623034633530326335646231393533346634303862656132616535373065363765626263313761643631393132613464666639220a62616c616e6365203d202231303030303030303030303030303030303030303030303030303030303030303030220a0a5b6163636f756e74732e76616c696461746f725d0a626f6e6465645f616d6f756e74203d202231303030303030303030303030303030303032220a64656c65676174696f6e5f72617465203d20320a0a232056414c494441544f5220332e0a5b5b6163636f756e74735d5d0a7075626c69635f6b6579203d2022303164616566663338613661623838623038376364633433323138616165643332323239623731663665383162613732643631613163653536336131323563346239220a62616c616e6365203d202231303030303030303030303030303030303030303030303030303030303030303030220a0a5b6163636f756e74732e76616c696461746f725d0a626f6e6465645f616d6f756e74203d202231303030303030303030303030303030303033220a64656c65676174696f6e5f72617465203d20330a0a232056414c494441544f5220342e0a5b5b6163636f756e74735d5d0a7075626c69635f6b6579203d2022303166373264623934616534363337306563656539643964393433333863373337303435623261336436666434366562326636376165346639323166326264633738220a62616c616e6365203d202231303030303030303030303030303030303030303030303030303030303030303030220a0a5b6163636f756e74732e76616c696461746f725d0a626f6e6465645f616d6f756e74203d202231303030303030303030303030303030303034220a64656c65676174696f6e5f72617465203d20340a0a232056414c494441544f5220352e0a5b5b6163636f756e74735d5d0a7075626c69635f6b6579203d2022303163383166616461326265306661326333363935376331336532333636643365346639393466343863643932376439313138613866346433366361303034636231220a62616c616e6365203d202231303030303030303030303030303030303030303030303030303030303030303030220a0a5b6163636f756e74732e76616c696461746f725d0a626f6e6465645f616d6f756e74203d202231303030303030303030303030303030303035220a64656c65676174696f6e5f72617465203d20350a0a232056414c494441544f5220362e0a5b5b6163636f756e74735d5d0a7075626c69635f6b6579203d2022303139366336616136343737303735336166653739636465346132643266316331336635656131653130616336356365373036623466636566666339383432323634220a62616c616e6365203d202231303030303030303030303030303030303030303030303030303030303030303030220a0a232056414c494441544f5220372e0a5b5b6163636f756e74735d5d0a7075626c69635f6b6579203d2022303161656561313664653135643038363265616364633133316262366233616637313465616365313930633235343239633366636237646539393030303038313137220a62616c616e6365203d202231303030303030303030303030303030303030303030303030303030303030303030220a0a232056414c494441544f5220382e0a5b5b6163636f756e74735d5d0a7075626c69635f6b6579203d2022303164663031623561613262306233333637366563383964383534323637376330656533323662336334663066313530393534613030616366663435373261316362220a62616c616e6365203d202231303030303030303030303030303030303030303030303030303030303030303030220a0a232056414c494441544f5220392e0a5b5b6163636f756e74735d5d0a7075626c69635f6b6579203d2022303138613039616331326631373662613335383566333134306663346465303665626433323835633065653064366566353639636535663762656334303365646337220a62616c616e6365203d202231303030303030303030303030303030303030303030303030303030303030303030220a0a232056414c494441544f522031302e0a5b5b6163636f756e74735d5d0a7075626c69635f6b6579203d2022303163663662366136396165393232386431383263666364363761353538323536303862373966643633373061393433616263353564336564653461366337623639220a62616c616e6365203d202231303030303030303030303030303030303030303030303030303030303030303030220a0a23205553455220312e0a5b5b64656c656761746f72735d5d0a76616c696461746f725f7075626c69635f6b6579203d2022303131353339346431663339356138376466656434616236326262666263393162353733626262326266666232633865626239633234306335316439356263633464220a64656c656761746f725f7075626c69635f6b6579203d2022303139633138343937356266373736376131383162363263643536376532363462363834613836343337663537636466333630663137633330653336663534653135220a62616c616e6365203d202231303030303030303030303030303030303030303030303030303030303030303030220a64656c6567617465645f616d6f756e74203d202231303030303030303030303030303030303031220a0a23205553455220322e0a5b5b64656c656761746f72735d5d0a76616c696461746f725f7075626c69635f6b6579203d2022303137393134653637303332616662623034633530326335646231393533346634303862656132616535373065363765626263313761643631393132613464666639220a64656c656761746f725f7075626c69635f6b6579203d2022303164386666613562303261333561326265313065646634336239333236323230333735643233306235653233663937386638393930663561333066656230623531220a62616c616e6365203d202231303030303030303030303030303030303030303030303030303030303030303030220a64656c6567617465645f616d6f756e74203d202231303030303030303030303030303030303032220a0a23205553455220332e0a5b5b64656c656761746f72735d5d0a76616c696461746f725f7075626c69635f6b6579203d2022303164616566663338613661623838623038376364633433323138616165643332323239623731663665383162613732643631613163653536336131323563346239220a64656c656761746f725f7075626c69635f6b6579203d2022303133626230393662313532343562353932623530633763646263313330643730313235663461633565633333313263343732393363383064343464646564316163220a62616c616e6365203d202231303030303030303030303030303030303030303030303030303030303030303030220a64656c6567617465645f616d6f756e74203d202231303030303030303030303030303030303033220a0a23205553455220342e0a5b5b64656c656761746f72735d5d0a76616c696461746f725f7075626c69635f6b6579203d2022303166373264623934616534363337306563656539643964393433333863373337303435623261336436666434366562326636376165346639323166326264633738220a64656c656761746f725f7075626c69635f6b6579203d2022303135323537353462653365376431656439633938656135323461333736613334316136393564636338363463393966303565636332386664643264663231303433220a62616c616e6365203d202231303030303030303030303030303030303030303030303030303030303030303030220a64656c6567617465645f616d6f756e74203d202231303030303030303030303030303030303034220a0a23205553455220352e0a5b5b64656c656761746f72735d5d0a76616c696461746f725f7075626c69635f6b6579203d2022303163383166616461326265306661326333363935376331336532333636643365346639393466343863643932376439313138613866346433366361303034636231220a64656c656761746f725f7075626c69635f6b6579203d2022303132643332666161386166313861353465663934356532353261633265323764333963353138663134633230393035336335663334623361303436313862383765220a62616c616e6365203d202231303030303030303030303030303030303030303030303030303030303030303030220a64656c6567617465645f616d6f756e74203d202231303030303030303030303030303030303035220a0a23205553455220362e0a5b5b6163636f756e74735d5d0a7075626c69635f6b6579203d2022303135316631303237643134353863313435616535636238633465653435656633346463623732366433653036323030636563393665373938616436313064616135220a62616c616e6365203d202231303030303030303030303030303030303030303030303030303030303030303030220a0a23205553455220372e0a5b5b6163636f756e74735d5d0a7075626c69635f6b6579203d2022303166643037363337326661653132663463353162613236383334656535303537643666336132666234313731316336653236343033623939306333323834623536220a62616c616e6365203d202231303030303030303030303030303030303030303030303030303030303030303030220a0a23205553455220382e0a5b5b6163636f756e74735d5d0a7075626c69635f6b6579203d2022303131326663333933646563373539636363356362346239663563623030333139383664663463346165313236663632653566616166313265346166333666626636220a62616c616e6365203d202231303030303030303030303030303030303030303030303030303030303030303030220a0a23205553455220392e0a5b5b6163636f756e74735d5d0a7075626c69635f6b6579203d2022303137663561333264613964393137336365313132643630383639353233343230353565626364663033396130313638656366613466383339343734343337303935220a62616c616e6365203d202231303030303030303030303030303030303030303030303030303030303030303030220a0a2320555345522031302e0a5b5b6163636f756e74735d5d0a7075626c69635f6b6579203d2022303134326661383865653936316433383762303037663766326465346232363364316663323238366462333862393066386130613863303634393336636436343766220a62616c616e6365203d202231303030303030303030303030303030303030303030303030303030303030303030220a", + "maybe_global_state_bytes": null + } + } +} \ No newline at end of file diff --git a/tests/data/rpc_response/get_status.json b/tests/data/rpc_response/get_status.json index 61f826f..fef6d4e 100644 --- a/tests/data/rpc_response/get_status.json +++ b/tests/data/rpc_response/get_status.json @@ -1,1068 +1,53 @@ { "jsonrpc": "2.0", - "id": "1", + "id": "0", "result": { - "api_version": "1.4.15", - "chainspec_name": "casper-test", - "starting_state_root_hash": "4c3856bd6a95b566301b9da61aaf84589a51ee2980f3cc7bbef78e7745386955", "peers": [ { - "node_id": "tls:00eb..ac11", - "address": "65.109.17.120:35000" + "node_id": "tls:11a8..bd2e", + "address": "127.0.0.1:22103" }, { - "node_id": "tls:0194..e850", - "address": "78.46.32.13:35000" + "node_id": "tls:55dc..5942", + "address": "127.0.0.1:22102" }, { - "node_id": "tls:021f..4b7a", - "address": "31.220.88.94:44050" + "node_id": "tls:6be4..cf82", + "address": "127.0.0.1:22104" }, { - "node_id": "tls:025d..b2d8", - "address": "85.114.132.133:35000" - }, - { - "node_id": "tls:034c..dd84", - "address": "51.158.55.55:55784" - }, - { - "node_id": "tls:039a..5ec2", - "address": "135.181.208.231:35000" - }, - { - "node_id": "tls:0454..aafb", - "address": "95.216.1.154:35000" - }, - { - "node_id": "tls:04db..0cdc", - "address": "65.21.75.254:35000" - }, - { - "node_id": "tls:0531..82b9", - "address": "116.202.169.210:35000" - }, - { - "node_id": "tls:05c9..3304", - "address": "65.21.205.159:35000" - }, - { - "node_id": "tls:05d2..2f08", - "address": "65.108.11.90:35000" - }, - { - "node_id": "tls:0670..f51a", - "address": "65.21.239.31:35000" - }, - { - "node_id": "tls:0671..e81b", - "address": "89.58.58.118:35000" - }, - { - "node_id": "tls:0676..5e5d", - "address": "136.243.187.84:35000" - }, - { - "node_id": "tls:06fd..c6e8", - "address": "162.55.63.245:35000" - }, - { - "node_id": "tls:0769..64cc", - "address": "178.63.63.89:35000" - }, - { - "node_id": "tls:07bb..fa83", - "address": "65.108.2.35:35000" - }, - { - "node_id": "tls:092a..e75d", - "address": "65.108.0.107:35000" - }, - { - "node_id": "tls:0a06..28dc", - "address": "89.58.2.198:35000" - }, - { - "node_id": "tls:0ab4..8c65", - "address": "65.21.134.245:35000" - }, - { - "node_id": "tls:0c2c..6d25", - "address": "45.32.28.180:35000" - }, - { - "node_id": "tls:0c2d..b70e", - "address": "65.21.132.234:35000" - }, - { - "node_id": "tls:0c5d..d687", - "address": "135.181.165.97:35000" - }, - { - "node_id": "tls:0ce3..dcde", - "address": "51.158.201.207:55760" - }, - { - "node_id": "tls:0d33..7356", - "address": "65.21.234.60:35000" - }, - { - "node_id": "tls:0d38..edf5", - "address": "51.158.55.55:56090" - }, - { - "node_id": "tls:0e7d..dd00", - "address": "94.130.140.91:35000" - }, - { - "node_id": "tls:0e7d..ee28", - "address": "3.129.252.116:35000" - }, - { - "node_id": "tls:0f70..7a73", - "address": "178.63.75.44:35000" - }, - { - "node_id": "tls:0ff8..b876", - "address": "46.4.32.165:35000" - }, - { - "node_id": "tls:108e..c8e5", - "address": "162.55.85.92:35000" - }, - { - "node_id": "tls:1139..f606", - "address": "35.91.110.58:35000" - }, - { - "node_id": "tls:1461..5977", - "address": "135.181.113.209:35000" - }, - { - "node_id": "tls:16b2..6587", - "address": "95.216.44.9:35000" - }, - { - "node_id": "tls:19df..417f", - "address": "148.251.90.119:35000" - }, - { - "node_id": "tls:1c4d..0043", - "address": "51.158.201.217:48894" - }, - { - "node_id": "tls:1ebf..31c9", - "address": "88.99.70.162:35000" - }, - { - "node_id": "tls:1f61..b47c", - "address": "65.108.101.19:35000" - }, - { - "node_id": "tls:1f78..b47f", - "address": "95.214.55.182:35000" - }, - { - "node_id": "tls:1f9a..3e35", - "address": "3.208.91.63:35000" - }, - { - "node_id": "tls:2217..1c00", - "address": "65.21.124.134:35000" - }, - { - "node_id": "tls:222c..f9ce", - "address": "65.21.235.239:35000" - }, - { - "node_id": "tls:2313..09d5", - "address": "103.104.75.222:35000" - }, - { - "node_id": "tls:237a..fd40", - "address": "95.216.240.135:35000" - }, - { - "node_id": "tls:2452..209f", - "address": "95.216.71.88:35000" - }, - { - "node_id": "tls:248d..e30f", - "address": "188.40.47.161:35000" - }, - { - "node_id": "tls:2517..1c2b", - "address": "95.214.55.66:35000" - }, - { - "node_id": "tls:2759..f45d", - "address": "65.21.92.145:35000" - }, - { - "node_id": "tls:2769..51fa", - "address": "141.94.194.38:35000" - }, - { - "node_id": "tls:28ed..4019", - "address": "159.69.73.104:35000" - }, - { - "node_id": "tls:2c6b..29bd", - "address": "65.21.233.253:35000" - }, - { - "node_id": "tls:2c88..f8ba", - "address": "88.99.60.204:35000" - }, - { - "node_id": "tls:2cff..b314", - "address": "144.76.158.197:35000" - }, - { - "node_id": "tls:2dda..d213", - "address": "65.108.73.148:35000" - }, - { - "node_id": "tls:2de5..987c", - "address": "95.216.116.53:35000" - }, - { - "node_id": "tls:2ff0..0747", - "address": "195.201.106.180:35000" - }, - { - "node_id": "tls:3065..35be", - "address": "65.21.226.33:35000" - }, - { - "node_id": "tls:3068..981b", - "address": "65.109.16.79:35151" - }, - { - "node_id": "tls:325e..5d20", - "address": "65.21.229.213:35000" - }, - { - "node_id": "tls:33e4..7704", - "address": "65.21.239.114:35000" - }, - { - "node_id": "tls:341c..39b0", - "address": "3.15.74.20:35000" - }, - { - "node_id": "tls:3646..acc0", - "address": "195.201.174.222:35000" - }, - { - "node_id": "tls:388d..db38", - "address": "18.167.47.162:35000" - }, - { - "node_id": "tls:3bce..1efd", - "address": "195.201.167.179:35000" - }, - { - "node_id": "tls:3e1c..9425", - "address": "135.181.114.117:35000" - }, - { - "node_id": "tls:3e90..623f", - "address": "46.4.119.228:35000" - }, - { - "node_id": "tls:4043..ce83", - "address": "89.58.31.153:35000" - }, - { - "node_id": "tls:405a..fa74", - "address": "78.46.68.30:35000" - }, - { - "node_id": "tls:418e..b92c", - "address": "65.108.43.219:35000" - }, - { - "node_id": "tls:43b3..1f51", - "address": "142.4.215.112:35000" - }, - { - "node_id": "tls:44ff..2186", - "address": "65.108.11.103:35000" - }, - { - "node_id": "tls:4569..b26b", - "address": "185.241.151.67:35000" - }, - { - "node_id": "tls:4588..25ab", - "address": "88.99.0.42:35000" - }, - { - "node_id": "tls:45af..3a0e", - "address": "65.21.194.138:35000" - }, - { - "node_id": "tls:45fd..3a63", - "address": "135.181.214.9:35000" - }, - { - "node_id": "tls:461f..1a28", - "address": "195.154.169.193:35000" - }, - { - "node_id": "tls:470c..b737", - "address": "81.30.157.85:35000" - }, - { - "node_id": "tls:4953..9ad7", - "address": "89.58.58.2:35000" - }, - { - "node_id": "tls:49c4..61f6", - "address": "138.201.53.13:35000" - }, - { - "node_id": "tls:4a8f..35d1", - "address": "65.108.73.113:35000" - }, - { - "node_id": "tls:4b48..42e0", - "address": "89.58.58.196:35000" - }, - { - "node_id": "tls:5016..b28d", - "address": "65.21.235.219:35000" - }, - { - "node_id": "tls:5100..f382", - "address": "162.55.6.177:35000" - }, - { - "node_id": "tls:5206..3c03", - "address": "88.99.143.246:35000" - }, - { - "node_id": "tls:5208..a376", - "address": "13.52.2.182:35000" - }, - { - "node_id": "tls:53db..6315", - "address": "65.108.4.27:35000" - }, - { - "node_id": "tls:543d..b0eb", - "address": "65.21.88.221:35000" - }, - { - "node_id": "tls:565b..389f", - "address": "5.9.6.115:35000" - }, - { - "node_id": "tls:5880..a086", - "address": "91.102.117.130:35000" - }, - { - "node_id": "tls:5894..5909", - "address": "65.21.237.160:35000" - }, - { - "node_id": "tls:5abe..bc92", - "address": "65.21.231.87:35000" - }, - { - "node_id": "tls:5cab..69c4", - "address": "65.108.0.22:35000" - }, - { - "node_id": "tls:5d22..f861", - "address": "93.190.141.13:35000" - }, - { - "node_id": "tls:5d92..7980", - "address": "35.93.118.23:9021" - }, - { - "node_id": "tls:5e0f..f13e", - "address": "88.99.4.9:35000" - }, - { - "node_id": "tls:5ee3..4af9", - "address": "65.108.4.79:35000" - }, - { - "node_id": "tls:5eef..3b7a", - "address": "157.90.130.143:35000" - }, - { - "node_id": "tls:61db..987e", - "address": "65.21.238.229:35000" - }, - { - "node_id": "tls:62c2..65a7", - "address": "136.243.147.249:35000" - }, - { - "node_id": "tls:633e..76cc", - "address": "95.217.115.123:35000" - }, - { - "node_id": "tls:6481..03d6", - "address": "65.109.28.177:35000" - }, - { - "node_id": "tls:6897..f929", - "address": "138.201.51.197:35000" - }, - { - "node_id": "tls:68ed..4497", - "address": "135.181.140.236:35000" - }, - { - "node_id": "tls:6934..50ed", - "address": "95.216.37.50:35000" - }, - { - "node_id": "tls:6a45..af4c", - "address": "65.108.2.45:35000" - }, - { - "node_id": "tls:6afc..7733", - "address": "51.158.201.207:50084" - }, - { - "node_id": "tls:6cad..9e6a", - "address": "38.242.205.7:35000" - }, - { - "node_id": "tls:6d42..9f9f", - "address": "135.181.207.1:35000" - }, - { - "node_id": "tls:6dc8..57b6", - "address": "95.217.144.180:35000" - }, - { - "node_id": "tls:6e7a..0179", - "address": "5.9.77.72:35000" - }, - { - "node_id": "tls:6eb9..3998", - "address": "65.109.158.239:35000" - }, - { - "node_id": "tls:71f9..8941", - "address": "65.21.204.190:35000" - }, - { - "node_id": "tls:75a9..989f", - "address": "65.21.227.126:35000" - }, - { - "node_id": "tls:75c4..8114", - "address": "89.58.58.83:35000" - }, - { - "node_id": "tls:76c3..42af", - "address": "65.21.88.62:35000" - }, - { - "node_id": "tls:77f1..221e", - "address": "65.21.134.245:49848" - }, - { - "node_id": "tls:78cb..e4be", - "address": "138.201.36.95:35000" - }, - { - "node_id": "tls:7910..2d1c", - "address": "18.210.121.229:35000" - }, - { - "node_id": "tls:7955..e178", - "address": "93.186.201.14:35000" - }, - { - "node_id": "tls:7967..fd08", - "address": "44.208.234.65:35000" - }, - { - "node_id": "tls:79a4..fd87", - "address": "95.217.62.236:35000" - }, - { - "node_id": "tls:7a30..f877", - "address": "89.58.58.148:35000" - }, - { - "node_id": "tls:7baf..df81", - "address": "116.202.82.28:35000" - }, - { - "node_id": "tls:7d12..bb10", - "address": "159.69.142.239:35000" - }, - { - "node_id": "tls:7d3a..5ae0", - "address": "138.201.54.44:35000" - }, - { - "node_id": "tls:7da6..db77", - "address": "69.57.160.57:35000" - }, - { - "node_id": "tls:80aa..e813", - "address": "107.155.109.42:35000" - }, - { - "node_id": "tls:8129..15cf", - "address": "65.21.120.160:35000" - }, - { - "node_id": "tls:8225..4634", - "address": "138.201.199.100:35000" - }, - { - "node_id": "tls:861f..8588", - "address": "23.92.69.78:35000" - }, - { - "node_id": "tls:863f..2f05", - "address": "65.108.5.248:35000" - }, - { - "node_id": "tls:870a..dac2", - "address": "148.251.9.155:35000" - }, - { - "node_id": "tls:87b8..c8e7", - "address": "65.21.204.180:35000" - }, - { - "node_id": "tls:8812..8191", - "address": "148.251.79.153:35000" - }, - { - "node_id": "tls:8909..6380", - "address": "212.90.121.143:35000" - }, - { - "node_id": "tls:89db..fda9", - "address": "51.159.221.68:60344" - }, - { - "node_id": "tls:89f5..cb8a", - "address": "135.181.132.246:35000" - }, - { - "node_id": "tls:8bca..edc6", - "address": "65.108.12.160:35000" - }, - { - "node_id": "tls:8cb2..6efd", - "address": "88.99.141.148:35000" - }, - { - "node_id": "tls:8cf4..b892", - "address": "190.102.106.18:35000" - }, - { - "node_id": "tls:8da4..3ad0", - "address": "18.236.230.32:35000" - }, - { - "node_id": "tls:8e5e..b596", - "address": "65.21.231.17:35000" - }, - { - "node_id": "tls:8e77..9fa3", - "address": "65.108.104.176:35000" - }, - { - "node_id": "tls:8f84..e153", - "address": "89.58.53.128:35000" - }, - { - "node_id": "tls:8ff6..f14b", - "address": "65.21.72.209:35000" - }, - { - "node_id": "tls:9178..af33", - "address": "65.108.4.145:35000" - }, - { - "node_id": "tls:91c2..b30b", - "address": "65.21.238.244:35000" - }, - { - "node_id": "tls:92cd..9d00", - "address": "3.23.146.54:35000" - }, - { - "node_id": "tls:92e3..8fef", - "address": "23.88.0.163:35000" - }, - { - "node_id": "tls:9318..6ce2", - "address": "54.193.230.87:35000" - }, - { - "node_id": "tls:9390..96f7", - "address": "94.130.236.189:35000" - }, - { - "node_id": "tls:9532..d84c", - "address": "95.216.247.164:45268" - }, - { - "node_id": "tls:9573..f7bb", - "address": "5.45.108.18:35000" - }, - { - "node_id": "tls:9575..eee3", - "address": "15.207.67.235:35000" - }, - { - "node_id": "tls:95de..489f", - "address": "65.21.227.35:35000" - }, - { - "node_id": "tls:95e1..8d7f", - "address": "157.90.34.213:35000" - }, - { - "node_id": "tls:9605..6f20", - "address": "88.99.94.214:35000" - }, - { - "node_id": "tls:97fc..2889", - "address": "65.108.8.30:35000" - }, - { - "node_id": "tls:992e..e207", - "address": "195.201.194.160:35000" - }, - { - "node_id": "tls:9a52..fea7", - "address": "54.244.29.172:35000" - }, - { - "node_id": "tls:9b26..aa2c", - "address": "65.108.199.53:35000" - }, - { - "node_id": "tls:9c59..dcb3", - "address": "5.9.21.244:35000" - }, - { - "node_id": "tls:9d74..b9e1", - "address": "88.99.89.209:35000" - }, - { - "node_id": "tls:9ed5..b3ff", - "address": "148.251.81.170:35000" - }, - { - "node_id": "tls:a161..2a93", - "address": "69.57.160.57:2340" - }, - { - "node_id": "tls:a352..5f8e", - "address": "144.76.238.62:35000" - }, - { - "node_id": "tls:a4b1..ae41", - "address": "65.108.41.164:35000" - }, - { - "node_id": "tls:a81b..ee09", - "address": "89.58.30.252:35000" - }, - { - "node_id": "tls:a928..1810", - "address": "144.76.110.71:35000" - }, - { - "node_id": "tls:ab62..8bd3", - "address": "138.201.48.72:35000" - }, - { - "node_id": "tls:abc4..89aa", - "address": "65.108.2.46:35000" - }, - { - "node_id": "tls:ac77..9e20", - "address": "3.136.227.9:35000" - }, - { - "node_id": "tls:ac8f..6664", - "address": "135.181.165.233:35000" - }, - { - "node_id": "tls:ad04..8cb2", - "address": "65.108.1.61:35000" - }, - { - "node_id": "tls:ad74..e8c2", - "address": "109.236.83.153:35000" - }, - { - "node_id": "tls:ad77..6268", - "address": "65.21.135.137:35000" - }, - { - "node_id": "tls:ae5a..e608", - "address": "95.216.45.210:35000" - }, - { - "node_id": "tls:ae86..399c", - "address": "65.21.33.37:35000" - }, - { - "node_id": "tls:af99..338d", - "address": "116.202.49.122:35000" - }, - { - "node_id": "tls:af9d..fbcf", - "address": "65.108.2.223:35000" - }, - { - "node_id": "tls:b123..a524", - "address": "65.108.0.43:35000" - }, - { - "node_id": "tls:b342..5b0c", - "address": "35.169.197.193:35000" - }, - { - "node_id": "tls:b34e..097d", - "address": "65.108.41.42:35000" - }, - { - "node_id": "tls:b3c6..0ced", - "address": "93.91.131.124:35000" - }, - { - "node_id": "tls:b3f1..f75c", - "address": "65.108.0.59:35000" - }, - { - "node_id": "tls:b457..0e60", - "address": "95.216.72.156:35000" - }, - { - "node_id": "tls:b6ba..5cfe", - "address": "168.119.138.106:35000" - }, - { - "node_id": "tls:b6bc..77d6", - "address": "116.202.170.231:35000" - }, - { - "node_id": "tls:b6d7..95cb", - "address": "95.216.67.144:35000" - }, - { - "node_id": "tls:b77d..f8cd", - "address": "65.21.233.95:35000" - }, - { - "node_id": "tls:b7b6..1a2c", - "address": "65.108.0.105:35000" - }, - { - "node_id": "tls:b7ba..e84f", - "address": "95.216.102.235:35000" - }, - { - "node_id": "tls:b7e6..1c80", - "address": "5.9.154.76:35000" - }, - { - "node_id": "tls:b950..7ff8", - "address": "65.21.238.219:35000" - }, - { - "node_id": "tls:ba66..374a", - "address": "159.69.75.172:35000" - }, - { - "node_id": "tls:bc49..ea0a", - "address": "54.195.153.185:35000" - }, - { - "node_id": "tls:bc80..b061", - "address": "65.108.5.253:35000" - }, - { - "node_id": "tls:bc88..fd12", - "address": "5.9.93.122:35000" - }, - { - "node_id": "tls:bd4a..7af6", - "address": "65.108.10.150:35000" - }, - { - "node_id": "tls:bd53..f2b2", - "address": "94.130.10.55:35000" - }, - { - "node_id": "tls:bd9c..4e49", - "address": "13.36.53.201:35000" - }, - { - "node_id": "tls:bf0d..c450", - "address": "65.21.227.101:35000" - }, - { - "node_id": "tls:c165..03c5", - "address": "54.191.55.103:35000" - }, - { - "node_id": "tls:c340..35df", - "address": "65.21.231.103:35000" - }, - { - "node_id": "tls:c683..3c48", - "address": "46.4.20.60:35000" - }, - { - "node_id": "tls:c753..13fa", - "address": "142.132.208.215:35000" - }, - { - "node_id": "tls:c9a7..cf61", - "address": "185.207.251.220:35000" - }, - { - "node_id": "tls:ccb6..9038", - "address": "65.108.0.148:35000" - }, - { - "node_id": "tls:cdaf..6486", - "address": "37.120.164.130:35000" - }, - { - "node_id": "tls:cdd1..2009", - "address": "65.21.236.40:35000" - }, - { - "node_id": "tls:d12f..a1f8", - "address": "65.108.42.61:35000" - }, - { - "node_id": "tls:d1fb..7b78", - "address": "213.202.212.222:35000" - }, - { - "node_id": "tls:d20f..ae7c", - "address": "95.216.10.102:35000" - }, - { - "node_id": "tls:d282..add0", - "address": "65.21.77.17:35000" - }, - { - "node_id": "tls:d41a..2cd0", - "address": "3.15.154.50:35000" - }, - { - "node_id": "tls:d496..f6f5", - "address": "65.21.236.44:35000" - }, - { - "node_id": "tls:d49d..c143", - "address": "213.239.207.87:35000" - }, - { - "node_id": "tls:d607..369a", - "address": "34.130.124.223:35000" - }, - { - "node_id": "tls:d69a..6ede", - "address": "65.21.238.180:35000" - }, - { - "node_id": "tls:d6b0..e8f1", - "address": "157.90.181.252:35000" - }, - { - "node_id": "tls:d7ac..5373", - "address": "65.108.46.187:35000" - }, - { - "node_id": "tls:d87b..3cab", - "address": "65.21.238.224:35000" - }, - { - "node_id": "tls:db58..1b47", - "address": "52.35.59.254:35000" - }, - { - "node_id": "tls:db9c..5efc", - "address": "18.163.249.168:35000" - }, - { - "node_id": "tls:deb8..fb1d", - "address": "65.21.231.90:35000" - }, - { - "node_id": "tls:debc..202e", - "address": "95.216.96.62:35000" - }, - { - "node_id": "tls:dff2..2403", - "address": "94.130.14.186:35000" - }, - { - "node_id": "tls:e2e0..5c22", - "address": "3.35.9.254:35000" - }, - { - "node_id": "tls:e6bf..d40f", - "address": "185.225.232.113:35000" - }, - { - "node_id": "tls:e6d5..fb46", - "address": "88.99.100.42:35000" - }, - { - "node_id": "tls:e70f..088f", - "address": "135.181.57.13:35000" - }, - { - "node_id": "tls:e749..e028", - "address": "65.21.231.29:35000" - }, - { - "node_id": "tls:e7ec..5878", - "address": "195.3.222.184:35000" - }, - { - "node_id": "tls:e8e4..e46c", - "address": "195.3.222.176:35000" - }, - { - "node_id": "tls:ea1f..fbbb", - "address": "95.216.11.106:35000" - }, - { - "node_id": "tls:ec90..f512", - "address": "95.216.67.162:35000" - }, - { - "node_id": "tls:ed2d..c530", - "address": "65.108.3.230:35000" - }, - { - "node_id": "tls:ee47..d6a8", - "address": "116.202.158.93:35000" - }, - { - "node_id": "tls:ef3e..c31e", - "address": "135.181.140.222:35000" - }, - { - "node_id": "tls:efc3..50f5", - "address": "135.181.216.142:35000" - }, - { - "node_id": "tls:f091..b61d", - "address": "88.99.209.137:35000" - }, - { - "node_id": "tls:f1a3..202b", - "address": "213.133.103.49:35000" - }, - { - "node_id": "tls:f1d9..5a7f", - "address": "136.243.137.238:35000" - }, - { - "node_id": "tls:f20e..6fbf", - "address": "95.216.42.190:35000" - }, - { - "node_id": "tls:f237..7713", - "address": "35.175.83.250:35000" - }, - { - "node_id": "tls:f46f..1523", - "address": "138.201.17.176:35000" - }, - { - "node_id": "tls:f483..9f5d", - "address": "168.119.147.38:35000" - }, - { - "node_id": "tls:f7b5..2b52", - "address": "65.108.0.50:35000" - }, - { - "node_id": "tls:f7fa..9234", - "address": "94.130.33.181:35000" - }, - { - "node_id": "tls:f87d..52ac", - "address": "76.91.193.251:35000" - }, - { - "node_id": "tls:f8e1..3f1c", - "address": "65.21.227.86:35000" - }, - { - "node_id": "tls:f8f5..6e5d", - "address": "138.201.122.209:35000" - }, - { - "node_id": "tls:fbb4..2a10", - "address": "65.108.140.73:35000" - }, - { - "node_id": "tls:fc57..b913", - "address": "142.132.131.170:35000" - }, - { - "node_id": "tls:fd7a..9e7f", - "address": "65.21.231.40:35000" - }, - { - "node_id": "tls:fd97..ced2", - "address": "89.58.56.197:35000" - }, - { - "node_id": "tls:fd98..64a5", - "address": "159.69.76.171:35000" - }, - { - "node_id": "tls:fe2d..3a79", - "address": "65.108.0.79:35000" - }, - { - "node_id": "tls:ff1f..664f", - "address": "135.181.74.237:35000" - }, - { - "node_id": "tls:ff3b..1b25", - "address": "89.58.59.217:35000" - }, - { - "node_id": "tls:ffc0..555b", - "address": "95.217.228.224:35000" + "node_id": "tls:b1ca..3f4b", + "address": "127.0.0.1:22105" } ], + "api_version": "1.0.0", + "build_version": "1.5.1-6873c86", + "chainspec_name": "casper-net-1", + "starting_state_root_hash": "f96888aa1e0f1d4ff573ea97ac57b56950e9ee97b1608d4469f9c83131675e78", "last_added_block_info": { - "hash": "8cd9b82ab53bcab84ece93fccf8c1b0bc1d9a679d7e61a4cc43443768f14cb1f", - "timestamp": "2023-05-18T08:43:43.488Z", - "era_id": 9181, - "height": 1732250, - "state_root_hash": "d923d8dc09643aa8be103e3a4d7257f09d5d09d0ad471fba8f7e8db6946a1c57", - "creator": "015da78bc6315643fbcf57d87a50853c67d8b271b615f38f6538f78a844cc4501d" + "hash": "4233cfc493996925354492b217287346f5c5cc76cdf9b83ad885d203e1e4ee7f", + "timestamp": "2023-07-12T15:19:18.784Z", + "era_id": 223, + "height": 2321, + "state_root_hash": "b3bb8e711b29b8fdb0ba93c4794e496802cbb478f548cb9d70055be7c236d3ce", + "creator": "01c81fada2be0fa2c36957c13e2366d3e4f994f48cd927d9118a8f4d36ca004cb1" + }, + "our_public_signing_key": "0115394d1f395a87dfed4ab62bbfbc91b573bbb2bffb2c8ebb9c240c51d95bcc4d", + "round_length": "4s 96ms", + "next_upgrade": { + "activation_point": 9904, + "protocol_version": "1.5.2" + }, + "uptime": "2months 13days 5h 37m 7s 171ms", + "reactor_state": "Validate", + "last_progress": "2023-07-12T12:31:32.550Z", + "available_block_range": { + "low": 0, + "high": 2321 }, - "our_public_signing_key": "0145fb72c75e1b459839555d70356a5e6172e706efa204d86c86050e2f7878960f", - "round_length": "32s 768ms", - "next_upgrade": null, - "build_version": "1.4.15-039d438f2-casper-mainnet", - "uptime": "13days 20h 40m 2s 205ms" + "block_sync": { + "historical": null, + "forward": null + } } } \ No newline at end of file diff --git a/tests/data/rpc_response/query_balance.json b/tests/data/rpc_response/query_balance.json new file mode 100644 index 0000000..0661d59 --- /dev/null +++ b/tests/data/rpc_response/query_balance.json @@ -0,0 +1,8 @@ +{ + "jsonrpc": "2.0", + "id": "122", + "result": { + "api_version": "1.0.0", + "balance": "1000000000000000000000000000000000" + } +} \ No newline at end of file diff --git a/tests/data/rpc_response/speculative_exec.json b/tests/data/rpc_response/speculative_exec.json new file mode 100644 index 0000000..1241e18 --- /dev/null +++ b/tests/data/rpc_response/speculative_exec.json @@ -0,0 +1,362 @@ +{ + "jsonrpc": "2.0", + "id": "1", + "result": { + "api_version": "1.0.0", + "block_hash": "1dd95f1d19fb96ebcbaa377de98cad991b30fce4aa8316eb2af0d7fa1f0276a6", + "execution_result": { + "Success": { + "effect": { + "operations": [], + "transforms": [ + { + "key": "hash-966042514ee882597168d9bfa7d93ebf05e68c3603ba0111ad2d68ea61d19406", + "transform": "Identity" + }, + { + "key": "hash-710fc25489533b4588ab4868ed1c75cc0fdda795a5919c80a81a7e1a8da94500", + "transform": "Identity" + }, + { + "key": "hash-710fc25489533b4588ab4868ed1c75cc0fdda795a5919c80a81a7e1a8da94500", + "transform": "Identity" + }, + { + "key": "hash-bc8808afcde5becf5a18a30f0a5dbe67fc79218cf401eec5c1d80533deb02da9", + "transform": "Identity" + }, + { + "key": "hash-710fc25489533b4588ab4868ed1c75cc0fdda795a5919c80a81a7e1a8da94500", + "transform": "Identity" + }, + { + "key": "uref-3ebfe099c11e38854ba2b454d5c32f89c0591a361a4e571d9d893687b61b6623-000", + "transform": { + "WriteCLValue": { + "cl_type": "Unit", + "bytes": "", + "parsed": null + } + } + }, + { + "key": "balance-3ebfe099c11e38854ba2b454d5c32f89c0591a361a4e571d9d893687b61b6623", + "transform": { + "WriteCLValue": { + "cl_type": "U512", + "bytes": "00", + "parsed": "0" + } + } + }, + { + "key": "account-hash-7c788a05c37e3200ef8cc8e7ffc2c89a2a4d6bd1ce91c2fd573a2b31221215f3", + "transform": { + "WriteAccount": "account-hash-7c788a05c37e3200ef8cc8e7ffc2c89a2a4d6bd1ce91c2fd573a2b31221215f3" + } + }, + { + "key": "account-hash-7c788a05c37e3200ef8cc8e7ffc2c89a2a4d6bd1ce91c2fd573a2b31221215f3", + "transform": "Identity" + }, + { + "key": "hash-966042514ee882597168d9bfa7d93ebf05e68c3603ba0111ad2d68ea61d19406", + "transform": "Identity" + }, + { + "key": "hash-966042514ee882597168d9bfa7d93ebf05e68c3603ba0111ad2d68ea61d19406", + "transform": "Identity" + }, + { + "key": "hash-1de2da707866883b58f66ce432637104109520d8473dcbfffbd12d3b4d13d1d5", + "transform": "Identity" + }, + { + "key": "hash-966042514ee882597168d9bfa7d93ebf05e68c3603ba0111ad2d68ea61d19406", + "transform": "Identity" + }, + { + "key": "hash-710fc25489533b4588ab4868ed1c75cc0fdda795a5919c80a81a7e1a8da94500", + "transform": "Identity" + }, + { + "key": "hash-710fc25489533b4588ab4868ed1c75cc0fdda795a5919c80a81a7e1a8da94500", + "transform": "Identity" + }, + { + "key": "hash-bc8808afcde5becf5a18a30f0a5dbe67fc79218cf401eec5c1d80533deb02da9", + "transform": "Identity" + }, + { + "key": "hash-710fc25489533b4588ab4868ed1c75cc0fdda795a5919c80a81a7e1a8da94500", + "transform": "Identity" + }, + { + "key": "balance-a4795635d4f331485d2cb63a96bf91ca70aa1348b96dd901facdfb41e97a7378", + "transform": "Identity" + }, + { + "key": "balance-78a517691f0b4e482598fe77eeb790ca5241731dc1069dda7e7a482a5c9bc96a", + "transform": "Identity" + }, + { + "key": "balance-a4795635d4f331485d2cb63a96bf91ca70aa1348b96dd901facdfb41e97a7378", + "transform": { + "WriteCLValue": { + "cl_type": "U512", + "bytes": "0e001f0afa095bc138938d44c64d31", + "parsed": "999999999999999999999999900000000" + } + } + }, + { + "key": "balance-78a517691f0b4e482598fe77eeb790ca5241731dc1069dda7e7a482a5c9bc96a", + "transform": { + "AddUInt512": "100000000" + } + }, + { + "key": "hash-966042514ee882597168d9bfa7d93ebf05e68c3603ba0111ad2d68ea61d19406", + "transform": "Identity" + }, + { + "key": "hash-710fc25489533b4588ab4868ed1c75cc0fdda795a5919c80a81a7e1a8da94500", + "transform": "Identity" + }, + { + "key": "hash-710fc25489533b4588ab4868ed1c75cc0fdda795a5919c80a81a7e1a8da94500", + "transform": "Identity" + }, + { + "key": "hash-bc8808afcde5becf5a18a30f0a5dbe67fc79218cf401eec5c1d80533deb02da9", + "transform": "Identity" + }, + { + "key": "hash-710fc25489533b4588ab4868ed1c75cc0fdda795a5919c80a81a7e1a8da94500", + "transform": "Identity" + }, + { + "key": "uref-3ebfe099c11e38854ba2b454d5c32f89c0591a361a4e571d9d893687b61b6623-000", + "transform": { + "WriteCLValue": { + "cl_type": "Unit", + "bytes": "", + "parsed": null + } + } + }, + { + "key": "balance-3ebfe099c11e38854ba2b454d5c32f89c0591a361a4e571d9d893687b61b6623", + "transform": { + "WriteCLValue": { + "cl_type": "U512", + "bytes": "00", + "parsed": "0" + } + } + }, + { + "key": "account-hash-7c788a05c37e3200ef8cc8e7ffc2c89a2a4d6bd1ce91c2fd573a2b31221215f3", + "transform": { + "WriteAccount": "account-hash-7c788a05c37e3200ef8cc8e7ffc2c89a2a4d6bd1ce91c2fd573a2b31221215f3" + } + }, + { + "key": "account-hash-7c788a05c37e3200ef8cc8e7ffc2c89a2a4d6bd1ce91c2fd573a2b31221215f3", + "transform": "Identity" + }, + { + "key": "hash-966042514ee882597168d9bfa7d93ebf05e68c3603ba0111ad2d68ea61d19406", + "transform": "Identity" + }, + { + "key": "hash-966042514ee882597168d9bfa7d93ebf05e68c3603ba0111ad2d68ea61d19406", + "transform": "Identity" + }, + { + "key": "hash-1de2da707866883b58f66ce432637104109520d8473dcbfffbd12d3b4d13d1d5", + "transform": "Identity" + }, + { + "key": "hash-966042514ee882597168d9bfa7d93ebf05e68c3603ba0111ad2d68ea61d19406", + "transform": "Identity" + }, + { + "key": "hash-710fc25489533b4588ab4868ed1c75cc0fdda795a5919c80a81a7e1a8da94500", + "transform": "Identity" + }, + { + "key": "hash-710fc25489533b4588ab4868ed1c75cc0fdda795a5919c80a81a7e1a8da94500", + "transform": "Identity" + }, + { + "key": "hash-bc8808afcde5becf5a18a30f0a5dbe67fc79218cf401eec5c1d80533deb02da9", + "transform": "Identity" + }, + { + "key": "hash-710fc25489533b4588ab4868ed1c75cc0fdda795a5919c80a81a7e1a8da94500", + "transform": "Identity" + }, + { + "key": "balance-a4795635d4f331485d2cb63a96bf91ca70aa1348b96dd901facdfb41e97a7378", + "transform": "Identity" + }, + { + "key": "balance-78a517691f0b4e482598fe77eeb790ca5241731dc1069dda7e7a482a5c9bc96a", + "transform": "Identity" + }, + { + "key": "balance-a4795635d4f331485d2cb63a96bf91ca70aa1348b96dd901facdfb41e97a7378", + "transform": { + "WriteCLValue": { + "cl_type": "U512", + "bytes": "0e001f0afa095bc138938d44c64d31", + "parsed": "999999999999999999999999900000000" + } + } + }, + { + "key": "balance-78a517691f0b4e482598fe77eeb790ca5241731dc1069dda7e7a482a5c9bc96a", + "transform": { + "AddUInt512": "100000000" + } + }, + { + "key": "hash-710fc25489533b4588ab4868ed1c75cc0fdda795a5919c80a81a7e1a8da94500", + "transform": "Identity" + }, + { + "key": "hash-710fc25489533b4588ab4868ed1c75cc0fdda795a5919c80a81a7e1a8da94500", + "transform": "Identity" + }, + { + "key": "hash-bc8808afcde5becf5a18a30f0a5dbe67fc79218cf401eec5c1d80533deb02da9", + "transform": "Identity" + }, + { + "key": "hash-710fc25489533b4588ab4868ed1c75cc0fdda795a5919c80a81a7e1a8da94500", + "transform": "Identity" + }, + { + "key": "balance-a4795635d4f331485d2cb63a96bf91ca70aa1348b96dd901facdfb41e97a7378", + "transform": "Identity" + }, + { + "key": "balance-3ebfe099c11e38854ba2b454d5c32f89c0591a361a4e571d9d893687b61b6623", + "transform": "Identity" + }, + { + "key": "balance-a4795635d4f331485d2cb63a96bf91ca70aa1348b96dd901facdfb41e97a7378", + "transform": { + "WriteCLValue": { + "cl_type": "U512", + "bytes": "0e00260765095bc138938d44c64d31", + "parsed": "999999999999999999999997400000000" + } + } + }, + { + "key": "balance-3ebfe099c11e38854ba2b454d5c32f89c0591a361a4e571d9d893687b61b6623", + "transform": { + "AddUInt512": "2500000000" + } + }, + { + "key": "transfer-3ebfe099c11e38854ba2b454d5c32f89c0591a361a4e571d9d893687b61b6623", + "transform": { + "WriteTransfer": { + "deploy_hash": "ccb36e4cbf6fa1c19406d571e36862060d35af708dab89ad6d9b937556f25c2c", + "from": "account-hash-4713806d69eb3ff1b65e16424c48746f23921324764e56b0f2978dd0b1488d7c", + "to": "account-hash-7c788a05c37e3200ef8cc8e7ffc2c89a2a4d6bd1ce91c2fd573a2b31221215f3", + "source": "uref-a4795635d4f331485d2cb63a96bf91ca70aa1348b96dd901facdfb41e97a7378-007", + "target": "uref-3ebfe099c11e38854ba2b454d5c32f89c0591a361a4e571d9d893687b61b6623-004", + "amount": "2500000000", + "gas": "0", + "id": 1 + } + } + }, + { + "key": "deploy-ccb36e4cbf6fa1c19406d571e36862060d35af708dab89ad6d9b937556f25c2c", + "transform": { + "WriteDeployInfo": { + "deploy_hash": "ccb36e4cbf6fa1c19406d571e36862060d35af708dab89ad6d9b937556f25c2c", + "transfers": [ + "transfer-3ebfe099c11e38854ba2b454d5c32f89c0591a361a4e571d9d893687b61b6623" + ], + "from": "account-hash-4713806d69eb3ff1b65e16424c48746f23921324764e56b0f2978dd0b1488d7c", + "source": "uref-a4795635d4f331485d2cb63a96bf91ca70aa1348b96dd901facdfb41e97a7378-007", + "gas": "100000000" + } + } + }, + { + "key": "hash-966042514ee882597168d9bfa7d93ebf05e68c3603ba0111ad2d68ea61d19406", + "transform": "Identity" + }, + { + "key": "hash-966042514ee882597168d9bfa7d93ebf05e68c3603ba0111ad2d68ea61d19406", + "transform": "Identity" + }, + { + "key": "hash-1de2da707866883b58f66ce432637104109520d8473dcbfffbd12d3b4d13d1d5", + "transform": "Identity" + }, + { + "key": "hash-966042514ee882597168d9bfa7d93ebf05e68c3603ba0111ad2d68ea61d19406", + "transform": "Identity" + }, + { + "key": "balance-78a517691f0b4e482598fe77eeb790ca5241731dc1069dda7e7a482a5c9bc96a", + "transform": "Identity" + }, + { + "key": "hash-966042514ee882597168d9bfa7d93ebf05e68c3603ba0111ad2d68ea61d19406", + "transform": "Identity" + }, + { + "key": "hash-710fc25489533b4588ab4868ed1c75cc0fdda795a5919c80a81a7e1a8da94500", + "transform": "Identity" + }, + { + "key": "hash-bc8808afcde5becf5a18a30f0a5dbe67fc79218cf401eec5c1d80533deb02da9", + "transform": "Identity" + }, + { + "key": "hash-710fc25489533b4588ab4868ed1c75cc0fdda795a5919c80a81a7e1a8da94500", + "transform": "Identity" + }, + { + "key": "balance-78a517691f0b4e482598fe77eeb790ca5241731dc1069dda7e7a482a5c9bc96a", + "transform": "Identity" + }, + { + "key": "balance-7202c568c0c5c1ddd19484cfe5cf6f9b2b8b1e59053375696041b6ec5c12e33c", + "transform": "Identity" + }, + { + "key": "balance-78a517691f0b4e482598fe77eeb790ca5241731dc1069dda7e7a482a5c9bc96a", + "transform": { + "WriteCLValue": { + "cl_type": "U512", + "bytes": "00", + "parsed": "0" + } + } + }, + { + "key": "balance-7202c568c0c5c1ddd19484cfe5cf6f9b2b8b1e59053375696041b6ec5c12e33c", + "transform": { + "AddUInt512": "100000000" + } + } + ] + }, + "transfers": [ + "transfer-3ebfe099c11e38854ba2b454d5c32f89c0591a361a4e571d9d893687b61b6623" + ], + "cost": "100000000" + } + } + } +} \ No newline at end of file diff --git a/tests/data/wasm/faucet.wasm b/tests/data/wasm/faucet.wasm new file mode 100644 index 0000000..cf36b4d Binary files /dev/null and b/tests/data/wasm/faucet.wasm differ diff --git a/tests/rpc/client_example_test.go b/tests/rpc/client_example_test.go index f21ae6a..1aa51bf 100644 --- a/tests/rpc/client_example_test.go +++ b/tests/rpc/client_example_test.go @@ -5,6 +5,7 @@ package rpc import ( "context" + "encoding/json" "net/http" "net/http/httptest" "os" @@ -16,6 +17,7 @@ import ( "github.com/make-software/casper-go-sdk/casper" "github.com/make-software/casper-go-sdk/rpc" "github.com/make-software/casper-go-sdk/tests/helper" + "github.com/make-software/casper-go-sdk/types" ) func Test_DefaultClient_GetDeploy_Example(t *testing.T) { @@ -70,3 +72,15 @@ func Test_Client_WithRetries_GetDeploy(t *testing.T) { _, err := client.GetDeploy(context.Background(), deployHash) assert.Error(t, err) } + +func Test_SpeculativeExec(t *testing.T) { + fixture, err := os.ReadFile("../data/deploy/deploy_with_transfer.json") + require.NoError(t, err) + var deployFixture types.Deploy + err = json.Unmarshal(fixture, &deployFixture) + require.NoError(t, err) + client := rpc.NewSpeculativeClient(casper.NewRPCHandler("http://127.0.0.1:25102/rpc", http.DefaultClient)) + result, err := client.SpeculativeExec(context.Background(), deployFixture, nil) + require.NoError(t, err) + assert.Equal(t, uint64(100000000), result.ExecutionResult.Success.Cost) +} diff --git a/tests/rpc/integration/put_deploy_test.go b/tests/rpc/integration/put_deploy_test.go new file mode 100644 index 0000000..0c7fc09 --- /dev/null +++ b/tests/rpc/integration/put_deploy_test.go @@ -0,0 +1,57 @@ +//go:build integration +// +build integration + +package integration + +import ( + "context" + "encoding/hex" + "log" + "math/big" + "net/http" + "os" + "testing" + "time" + + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" + + "github.com/make-software/casper-go-sdk/casper" + "github.com/make-software/casper-go-sdk/rpc" + "github.com/make-software/casper-go-sdk/types" + "github.com/make-software/casper-go-sdk/types/clvalue" +) + +func Test_PutDeploy(t *testing.T) { + facetKeys, err := casper.NewED25519PrivateKeyFromPEMFile("../../data/keys/docker-nctl-secret.pem") + require.NoError(t, err) + require.NoError(t, err) + header := types.DefaultHeader() + header.ChainName = "casper-net-1" + header.Account = facetKeys.PublicKey() + require.NoError(t, err) + header.Timestamp = types.Timestamp(time.Now()) + payment := types.StandardPayment(big.NewInt(4000000000)) + + moduleBytes, err := os.ReadFile("../../data/wasm/faucet.wasm") + require.NoError(t, err) + + args := &types.Args{} + args.AddArgument("target", clvalue.NewCLByteArray(facetKeys.PublicKey().AccountHash().Hash.Bytes())).AddArgument("amount", *clvalue.NewCLUInt512(big.NewInt(1000000000000))) + session := types.ExecutableDeployItem{ + ModuleBytes: &types.ModuleBytes{ + ModuleBytes: hex.EncodeToString(moduleBytes), + Args: args, + }, + } + + deploy, err := types.MakeDeploy(header, payment, session) + err = deploy.SignDeploy(facetKeys) + require.NoError(t, err) + + rpcClient := rpc.NewClient(rpc.NewHttpHandler("http://127.0.0.1:11101/rpc", http.DefaultClient)) + res, err := rpcClient.PutDeploy(context.Background(), *deploy) + log.Println(deploy.Hash.ToHex()) + require.NoError(t, err) + assert.NotEmpty(t, res.DeployHash) +} diff --git a/tests/rpc/rpc_client_integration_test.go b/tests/rpc/rpc_client_integration_test.go new file mode 100644 index 0000000..54cc3c1 --- /dev/null +++ b/tests/rpc/rpc_client_integration_test.go @@ -0,0 +1,34 @@ +//go:build integration +// +build integration + +package rpc + +import ( + "context" + "net/http" + "testing" + + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" + + "github.com/make-software/casper-go-sdk/casper" + "github.com/make-software/casper-go-sdk/rpc" +) + +func Test_QueryBalance_byPublicKey(t *testing.T) { + client := rpc.NewClient(rpc.NewHttpHandler("http://127.0.0.1:11101/rpc", http.DefaultClient)) + pubKey, err := casper.NewPublicKey("0115394d1f395a87dfed4ab62bbfbc91b573bbb2bffb2c8ebb9c240c51d95bcc4d") + require.NoError(t, err) + res, err := client.QueryBalance(context.Background(), rpc.PurseIdentifier{ + MainPurseUnderPublicKey: &pubKey, + }) + require.NoError(t, err) + assert.Equal(t, "1000000000000000000000000000000000", res.Balance.String()) +} + +func Test_GetChainspec(t *testing.T) { + client := rpc.NewClient(rpc.NewHttpHandler("http://127.0.0.1:11101/rpc", http.DefaultClient)) + res, err := client.GetChainspec(context.Background()) + require.NoError(t, err) + assert.NotEmpty(t, res.ChainspecBytes.ChainspecBytes) +} diff --git a/tests/rpc/rpc_client_test.go b/tests/rpc/rpc_client_test.go index 682c907..4af15cb 100644 --- a/tests/rpc/rpc_client_test.go +++ b/tests/rpc/rpc_client_test.go @@ -47,6 +47,16 @@ func Test_DefaultClient_GetDeploy(t *testing.T) { assert.Equal(t, deployHash, result.Deploy.Hash.ToHex()) } +func Test_DefaultClient_GetDeployFinalizedApproval(t *testing.T) { + server := SetupServer(t, "../data/deploy/get_raw_rpc_deploy.json") + defer server.Close() + client := casper.NewRPCClient(casper.NewRPCHandler(server.URL, http.DefaultClient)) + deployHash := "0009ea4441f4700325d9c38b0b6df415537596e1204abe4f6a94b6996aebf2f1" + result, err := client.GetDeployFinalizedApproval(context.Background(), deployHash) + require.NoError(t, err) + assert.Equal(t, deployHash, result.Deploy.Hash.ToHex()) +} + func Test_DefaultClient_GetStateItem_GetAccount(t *testing.T) { server := SetupServer(t, "../data/rpc_response/get_state_item_account.json") defer server.Close() @@ -116,6 +126,17 @@ func Test_DefaultClient_QueryGlobalStateByBlock_GetAccount(t *testing.T) { assert.NotEmpty(t, res.StoredValue.Account.AccountHash) } +func Test_DefaultClient_QueryGlobalStateByBlockHeight_GetAccount(t *testing.T) { + server := SetupServer(t, "../data/rpc_response/query_global_state_era.json") + defer server.Close() + client := casper.NewRPCClient(casper.NewRPCHandler(server.URL, http.DefaultClient)) + accountKey := "account-hash-e94daaff79c2ab8d9c31d9c3058d7d0a0dd31204a5638dc1451fa67b2e3fb88c" + res, err := client.QueryGlobalStateByBlockHeight(context.Background(), 1000, accountKey, nil) + require.NoError(t, err) + assert.NotEmpty(t, res.BlockHeader.BodyHash) + assert.NotEmpty(t, res.StoredValue.Account.AccountHash) +} + func Test_DefaultClient_QueryGlobalStateByBlock_GetWithdraw(t *testing.T) { server := SetupServer(t, "../data/rpc_response/query_global_state_withdraw.json") defer server.Close() @@ -394,3 +415,25 @@ func Test_DefaultClient_GetPeers(t *testing.T) { require.NoError(t, err) assert.NotEmpty(t, result.Peers) } + +func Test_DefaultClient_QueryBalance_byPublicKey(t *testing.T) { + server := SetupServer(t, "../data/rpc_response/query_balance.json") + defer server.Close() + pubKey, err := casper.NewPublicKey("0115394d1f395a87dfed4ab62bbfbc91b573bbb2bffb2c8ebb9c240c51d95bcc4d") + require.NoError(t, err) + client := casper.NewRPCClient(casper.NewRPCHandler(server.URL, http.DefaultClient)) + result, err := client.QueryBalance(context.Background(), rpc.PurseIdentifier{ + MainPurseUnderPublicKey: &pubKey, + }) + require.NoError(t, err) + assert.NotEmpty(t, result.Balance) +} + +func Test_DefaultClient_GetChainspec(t *testing.T) { + server := SetupServer(t, "../data/rpc_response/get_chainspec.json") + defer server.Close() + client := casper.NewRPCClient(casper.NewRPCHandler(server.URL, http.DefaultClient)) + result, err := client.GetChainspec(context.Background()) + require.NoError(t, err) + assert.NotEmpty(t, result.ChainspecBytes.ChainspecBytes) +} diff --git a/tests/rpc/rpc_speculative_test.go b/tests/rpc/rpc_speculative_test.go new file mode 100644 index 0000000..b32c3b2 --- /dev/null +++ b/tests/rpc/rpc_speculative_test.go @@ -0,0 +1,30 @@ +package rpc + +import ( + "context" + "encoding/json" + "net/http" + "os" + "testing" + + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" + + "github.com/make-software/casper-go-sdk/casper" + "github.com/make-software/casper-go-sdk/rpc" + "github.com/make-software/casper-go-sdk/types" +) + +func Test_Speculative_endpoint(t *testing.T) { + server := SetupServer(t, "../data/rpc_response/speculative_exec.json") + defer server.Close() + var deployFixture types.Deploy + fixture, err := os.ReadFile("../data/deploy/deploy_with_transfer.json") + require.NoError(t, err) + err = json.Unmarshal(fixture, &deployFixture) + require.NoError(t, err) + client := rpc.NewSpeculativeClient(casper.NewRPCHandler(server.URL, http.DefaultClient)) + result, err := client.SpeculativeExec(context.Background(), deployFixture, nil) + require.NoError(t, err) + assert.Equal(t, uint64(100000000), result.ExecutionResult.Success.Cost) +} diff --git a/tests/types/block_proposer_test.go b/tests/types/block_proposer_test.go new file mode 100644 index 0000000..0eea5d7 --- /dev/null +++ b/tests/types/block_proposer_test.go @@ -0,0 +1,52 @@ +package types + +import ( + "encoding/hex" + "testing" + + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" + + "github.com/make-software/casper-go-sdk/types" +) + +func Test_BlockProposer_Scan_System(t *testing.T) { + res := &types.Proposer{} + hexData, err := hex.DecodeString("00") + require.NoError(t, err) + err = res.Scan(hexData) + require.NoError(t, err) + assert.True(t, res.IsSystem()) +} + +func Test_BlockProposer_Scan_PublicKey(t *testing.T) { + res := &types.Proposer{} + hexData, err := hex.DecodeString("015a372b0e230bf9393e2df0b3de857bb0e17370884bb881f840cb1482bb2922cf") + require.NoError(t, err) + err = res.Scan(hexData) + require.NoError(t, err) + assert.False(t, res.IsSystem()) + publicKey, err := res.PublicKey() + require.NoError(t, err) + assert.Equal(t, "015a372b0e230bf9393e2df0b3de857bb0e17370884bb881f840cb1482bb2922cf", publicKey.ToHex()) +} + +func Test_BlockProposer_InvalidData(t *testing.T) { + res := &types.Proposer{} + err := res.Scan("0") + assert.Error(t, err) +} + +func Test_BlockProposer_Value_System(t *testing.T) { + res, err := types.NewProposer("00") + require.NoError(t, err) + assert.True(t, res.IsSystem()) +} + +func Test_BlockProposer_Value_PublicKey(t *testing.T) { + res, err := types.NewProposer("015a372b0e230bf9393e2df0b3de857bb0e17370884bb881f840cb1482bb2922cf") + require.NoError(t, err) + pubKey, err := res.PublicKey() + require.NoError(t, err) + assert.Equal(t, "015a372b0e230bf9393e2df0b3de857bb0e17370884bb881f840cb1482bb2922cf", pubKey.ToHex()) +} diff --git a/tests/types/block_test.go b/tests/types/block_test.go index aa7f91e..7890110 100644 --- a/tests/types/block_test.go +++ b/tests/types/block_test.go @@ -6,6 +6,7 @@ import ( "testing" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" "github.com/make-software/casper-go-sdk/types" ) @@ -35,3 +36,45 @@ func Test_BlockSwitch_MarshalUnmarshal_ShouldReturnSameResult(t *testing.T) { assert.NoError(t, err) assert.JSONEq(t, string(fixture), string(result)) } + +func Test_BlockSwitch_WithSystemProposal_MarshalUnmarshal_ShouldReturnSameResult(t *testing.T) { + fixture, err := os.ReadFile("../data/block/block_switch_system_proposer.json") + assert.NoError(t, err) + + var block types.Block + err = json.Unmarshal(fixture, &block) + assert.NoError(t, err) + + result, err := json.Marshal(block) + assert.NoError(t, err) + assert.JSONEq(t, string(fixture), string(result)) +} + +func Test_BlockSwitch_WithSystemProposal_IsSystem_ShouldReturnTrue(t *testing.T) { + fixture, err := os.ReadFile("../data/block/block_switch_system_proposer.json") + assert.NoError(t, err) + + var block types.Block + err = json.Unmarshal(fixture, &block) + require.NoError(t, err) + assert.True(t, block.Body.Proposer.IsSystem()) + _, err = block.Body.Proposer.PublicKey() + assert.Error(t, err) + pubKey := block.Body.Proposer.PublicKeyOptional() + assert.Nil(t, pubKey) +} + +func Test_BlockProposal_PublicKey_ShouldWorkForNormalBlock(t *testing.T) { + fixture, err := os.ReadFile("../data/block/block_example.json") + assert.NoError(t, err) + + var block types.Block + err = json.Unmarshal(fixture, &block) + require.NoError(t, err) + assert.False(t, block.Body.Proposer.IsSystem()) + result, err := block.Body.Proposer.PublicKey() + assert.NoError(t, err) + assert.Equal(t, "019e7b8bdec03ba83be4f5443d9f7f9111c77fec984ce9bb5bb7eb3da1e689c02d", result.String()) + pubKey := block.Body.Proposer.PublicKeyOptional() + assert.Equal(t, "019e7b8bdec03ba83be4f5443d9f7f9111c77fec984ce9bb5bb7eb3da1e689c02d", pubKey.String()) +} diff --git a/types/block.go b/types/block.go index 5bf27a0..01e0510 100644 --- a/types/block.go +++ b/types/block.go @@ -17,9 +17,9 @@ type BlockBody struct { // List of `Deploy` hashes included in the block DeployHashes []key.Hash `json:"deploy_hashes"` // Public key of the validator that proposed the block - Proposer keypair.PublicKey `json:"proposer"` + Proposer Proposer `json:"proposer"` // List of `TransferHash` hashes included in the block - TransferHashes []key.TransferHash `json:"transfer_hashes"` + TransferHashes []key.Hash `json:"transfer_hashes"` } type BlockHeader struct { diff --git a/types/block_proposer.go b/types/block_proposer.go new file mode 100644 index 0000000..e109aee --- /dev/null +++ b/types/block_proposer.go @@ -0,0 +1,88 @@ +package types + +import ( + "database/sql/driver" + "encoding/hex" + "encoding/json" + "errors" + + "github.com/make-software/casper-go-sdk/types/keypair" +) + +type Proposer struct { + isSystem bool + publicKey *keypair.PublicKey +} + +func NewProposer(src string) (Proposer, error) { + var result Proposer + if src == "00" { + result.isSystem = true + return result, nil + } + pubKey, err := keypair.NewPublicKey(src) + if err != nil { + return result, err + } + result.publicKey = &pubKey + return result, nil +} + +func (p Proposer) IsSystem() bool { + return p.isSystem +} + +func (p Proposer) PublicKey() (keypair.PublicKey, error) { + if p.IsSystem() { + return keypair.PublicKey{}, errors.New("system proposer doesn't have a PublicKey") + } + return *p.publicKey, nil +} + +func (p Proposer) PublicKeyOptional() *keypair.PublicKey { + return p.publicKey +} + +func (p Proposer) MarshalJSON() ([]byte, error) { + if p.isSystem { + return []byte(`"00"`), nil + } + return json.Marshal(p.publicKey) +} + +func (p *Proposer) UnmarshalJSON(bytes []byte) error { + var str string + err := json.Unmarshal(bytes, &str) + if err != nil { + return err + } + *p, err = NewProposer(str) + if err != nil { + return err + } + return nil +} + +func (p *Proposer) Scan(value any) error { + b, ok := value.([]byte) + if !ok { + return errors.New("invalid scan value type") + } + if hex.EncodeToString(b) == "00" { + p.isSystem = true + return nil + } + var pubKey keypair.PublicKey + if err := pubKey.Scan(value); err != nil { + return err + } + p.publicKey = &pubKey + return nil +} + +func (p Proposer) Value() (driver.Value, error) { + if p.isSystem { + return hex.DecodeString("00") + } + return p.publicKey.Value() +} diff --git a/types/contract_package.go b/types/contract_package.go index 5400424..8230e5d 100644 --- a/types/contract_package.go +++ b/types/contract_package.go @@ -13,7 +13,8 @@ type ContractPackage struct { // of the allowed groups is present in the caller’s context before execution. Groups []ContractGroup `json:"groups"` // List of active versions of a contract. - Versions []ContractVersion `json:"versions"` + Versions []ContractVersion `json:"versions"` + LockStatus string `json:"lock_status"` } // ContractGroup associate a set of URefs with a label.