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

Add API response tests from TIP examples #1687

Merged
merged 57 commits into from
Jan 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
57 commits
Select commit Hold shift + click to select a range
d0d14a3
Add API response tests from TIP examples
thibault-martinez Nov 27, 2023
305c02d
Add more
thibault-martinez Nov 27, 2023
ba6fd85
Add assert_response
thibault-martinez Nov 27, 2023
da8d6b7
More fixtures
thibault-martinez Nov 27, 2023
b6d5a86
Add assert_binary_response
thibault-martinez Nov 27, 2023
1e16822
Merge branch '2.0' into api-tips-example-test
thibault-martinez Nov 27, 2023
3c9759b
Parse all responses
thibault-martinez Nov 27, 2023
bc59268
Return result
thibault-martinez Nov 27, 2023
044a997
Comment failing tests
thibault-martinez Nov 27, 2023
66c0ebe
Uncomment ValidatorResponse
thibault-martinez Nov 27, 2023
620052c
Uncomment CommitteeResponse
thibault-martinez Nov 27, 2023
baf89a4
Merge branch '2.0' into api-tips-example-test
thibault-martinez Nov 27, 2023
f127831
Warning
thibault-martinez Nov 27, 2023
7a22fda
order!
thibault-martinez Nov 27, 2023
aab9618
Merge branch '2.0' into api-tips-example-test
thibault-martinez Dec 3, 2023
07f73be
Test updates
thibault-martinez Dec 3, 2023
90ec801
Merge branch '2.0' into api-tips-example-test
thibault-martinez Dec 6, 2023
d6daa88
Fix InfoResponse
thibault-martinez Dec 6, 2023
0a41434
Fix ValidatorResponse
thibault-martinez Dec 6, 2023
deb0284
Fix ManaRewardsResponse
thibault-martinez Dec 6, 2023
3c46a64
Fix CongestionResponse
thibault-martinez Dec 6, 2023
9f38c62
Improve binary_response
thibault-martinez Dec 6, 2023
c67d9be
Merge branch '2.0' into api-tips-example-test
thibault-martinez Dec 6, 2023
561c620
Fix UtxoChangesResponse
thibault-martinez Dec 6, 2023
151b803
Fix SlotCommitment
thibault-martinez Dec 6, 2023
c661e2a
Merge branch '2.0' into api-tips-example-test
thibault-martinez Dec 11, 2023
2445232
Fix InfoResponse test
thibault-martinez Dec 11, 2023
698b776
Fix IssuanceBlockHeaderResponse
thibault-martinez Dec 11, 2023
833861e
Merge branch '2.0' into api-tips-example-test
thibault-martinez Dec 11, 2023
a4d39eb
Fix OutputMetadata
thibault-martinez Dec 11, 2023
8aa1b34
OutputWithMetadata
thibault-martinez Dec 11, 2023
5defd34
Merge branch '2.0' into api-tips-example-test
thibault-martinez Dec 12, 2023
15e073b
Merge branch '2.0' into api-tips-example-test
thibault-martinez Jan 10, 2024
a5449dd
Merge branch '2.0' into api-tips-example-test
thibault-martinez Jan 11, 2024
a867a8c
Fix get-info-response-example
thibault-martinez Jan 11, 2024
d837c08
Fix get-mana-rewards-example
thibault-martinez Jan 11, 2024
fc1113e
Fix get-validators-example
thibault-martinez Jan 11, 2024
0ede853
Some block fixes
thibault-martinez Jan 11, 2024
06925b0
Merge branch '2.0' into api-tips-example-test
thibault-martinez Jan 12, 2024
837fce9
Merge branch '2.0' into api-tips-example-test
thibault-martinez Jan 12, 2024
fd24473
Merge branch '2.0' into api-tips-example-test
thibault-martinez Jan 18, 2024
093da97
BlockMetadataResponse
thibault-martinez Jan 18, 2024
df90ba8
Compare json values
thibault-martinez Jan 18, 2024
6388871
Merge branch '2.0' into api-tips-example-test
thibault-martinez Jan 22, 2024
7c28c56
Some fixes
thibault-martinez Jan 22, 2024
715350c
Add BlockWithMetadataResponse test
thibault-martinez Jan 22, 2024
4b41c90
Fix OutputResponse
thibault-martinez Jan 22, 2024
86c9afe
Fix OutputWithMetadata
thibault-martinez Jan 22, 2024
6f85281
Add TransactionMetadataResponse test
thibault-martinez Jan 22, 2024
38117a1
Add failing UtxoChangesFullResponse
thibault-martinez Jan 22, 2024
1ac43f6
Merge branch '2.0' into api-tips-example-test
thibault-martinez Jan 23, 2024
05379d4
Merge branch '2.0' into api-tips-example-test
thibault-martinez Jan 25, 2024
1db45bc
Two more fixes
thibault-martinez Jan 25, 2024
73982de
Nits
thibault-martinez Jan 25, 2024
df76616
Last tests
thibault-martinez Jan 25, 2024
a078334
Add TODO
thibault-martinez Jan 25, 2024
f9ada09
Copyright date
thibault-martinez Jan 25, 2024
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
103 changes: 103 additions & 0 deletions sdk/tests/types/api/core.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
// Copyright 2024 IOTA Stiftung
// SPDX-License-Identifier: Apache-2.0

use iota_sdk::types::{
api::core::{
BlockMetadataResponse, BlockWithMetadataResponse, CommitteeResponse, CongestionResponse, InfoResponse,
IssuanceBlockHeaderResponse, ManaRewardsResponse, OutputResponse, RoutesResponse, SubmitBlockResponse,
TransactionMetadataResponse, UtxoChangesFullResponse, UtxoChangesResponse, ValidatorResponse,
ValidatorsResponse,
},
block::{
output::{OutputMetadata, OutputWithMetadata},
slot::SlotCommitment,
BlockDto,
},
};
use packable::{
error::{UnexpectedEOF, UnpackError},
unpacker::SliceUnpacker,
Packable, PackableExt,
};
// use pretty_assertions::assert_eq;
use serde::{Deserialize, Serialize};

fn json_response<T>(path: &str) -> Result<T, serde_json::Error>
where
for<'a> T: Serialize + Deserialize<'a>,
{
let file = std::fs::read_to_string(&format!("./tests/types/api/fixtures/{path}")).unwrap();
let value_des = serde_json::from_str::<serde_json::Value>(&file)?;
let t = serde_json::from_value::<T>(value_des.clone())?;
// let value_ser = serde_json::to_value(&t)?;

// TODO https://github.com/iotaledger/iota-sdk/issues/1883
// assert_eq!(value_des, value_ser);

Ok(t)
}

fn binary_response<T: PackableExt>(
path: &str,
visitor: &T::UnpackVisitor,
) -> Result<T, UnpackError<<T as Packable>::UnpackError, UnexpectedEOF>> {
let file = std::fs::read_to_string(&format!("./tests/types/api/fixtures/{path}")).unwrap();
let bytes = hex::decode(file).unwrap();
let mut unpacker = SliceUnpacker::new(bytes.as_slice());
let res = T::unpack::<_, true>(&mut unpacker, visitor);

assert!(u8::unpack::<_, true>(&mut unpacker, &()).is_err());

res
}

#[test]
fn responses() {
// GET /api/routes
json_response::<RoutesResponse>("get-routes-response-example.json").unwrap();
// GET /api/core/v3/info
json_response::<InfoResponse>("get-info-response-example.json").unwrap();
// GET /api/core/v3/accounts/{bech32Address}/congestion
json_response::<CongestionResponse>("get-congestion-estimate-response-example.json").unwrap();
// GET /api/core/v3/rewards/{outputId}
json_response::<ManaRewardsResponse>("get-mana-rewards-example.json").unwrap();
// GET /api/core/v3/validators
json_response::<ValidatorsResponse>("get-validators-example.json").unwrap();
// GET /api/core/v3/validators/{bech32Address}
json_response::<ValidatorResponse>("get-validator-example.json").unwrap();
// GET /api/core/v3/committee
json_response::<CommitteeResponse>("get-committee-example.json").unwrap();
// GET /api/core/v3/blocks/issuance
json_response::<IssuanceBlockHeaderResponse>("get-buildingBlock-response-example.json").unwrap();
// POST /api/core/v3/blocks
json_response::<SubmitBlockResponse>("post-blocks-response-example.json").unwrap();
// GET /api/core/v3/blocks/{blockId}
json_response::<BlockDto>("get-block-by-id-empty-response-example.json").unwrap();
json_response::<BlockDto>("tagged-data-block-example.json").unwrap();
json_response::<BlockDto>("transaction-block-example.json").unwrap();
json_response::<BlockDto>("get-block-by-id-validation-response-example.json").unwrap();
// GET /api/core/v3/blocks/{blockId}/metadata
json_response::<BlockMetadataResponse>("get-block-by-id-response-example-new-transaction.json").unwrap();
json_response::<BlockMetadataResponse>("get-block-by-id-response-example-new.json").unwrap();
json_response::<BlockMetadataResponse>("get-block-by-id-response-example-confirmed-transaction.json").unwrap();
json_response::<BlockMetadataResponse>("get-block-by-id-response-example-confirmed.json").unwrap();
json_response::<BlockMetadataResponse>("get-block-by-id-response-example-conflicting-transaction.json").unwrap();
// GET /api/core/v3/blocks/{blockId}/full
json_response::<BlockWithMetadataResponse>("get-full-block-by-id-tagged-data-response-example.json").unwrap();
// GET /api/core/v3/outputs/{outputId}
json_response::<OutputResponse>("get-outputs-by-id-response-example.json").unwrap();
// GET /api/core/v3/outputs/{outputId}/metadata
json_response::<OutputMetadata>("get-output-metadata-by-id-response-unspent-example.json").unwrap();
json_response::<OutputMetadata>("get-output-metadata-by-id-response-spent-example.json").unwrap();
// GET /api/core/v3/outputs/{outputId}/full
json_response::<OutputWithMetadata>("get-full-output-metadata-example.json").unwrap();
// GET /api/core/v3/transactions/{transactionId}/metadata
Thoralf-M marked this conversation as resolved.
Show resolved Hide resolved
json_response::<TransactionMetadataResponse>("get-transaction-metadata-by-id-response-example.json").unwrap();
// GET /api/core/v3/commitments/{commitmentId}
json_response::<SlotCommitment>("get-commitment-response-example.json").unwrap();
binary_response::<SlotCommitment>("get-commitment-response-binary-example", &()).unwrap();
// GET /api/core/v3/commitments/{commitmentId}/utxo-changes
json_response::<UtxoChangesResponse>("get-utxo-changes-response-example.json").unwrap();
// GET /api/core/v3/commitments/{commitmentId}/utxo-changes/full
json_response::<UtxoChangesFullResponse>("get-utxo-changes-full-response-example.json").unwrap();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
"header": {
"protocolVersion": 3,
"networkId": "8342982141227064571",
"issuingTime": "1695275852000000000",
"slotCommitmentId": "0x3a1e3b617060146e0362361a4b752833186108395f3b2b3d3e6c655e287d70767ea58d2a",
"latestFinalizedSlot": 500,
"issuerId": "0x17432c5a7a672503480241125e3952414a7a320441080c624c264b004e09614a"
},
"body": {
"type": 0,
"strongParents": [
"0x27e0461873f37040c9e59c35ad8a106fa1b94f5ec9ef89499b31904f9a3de59be58dd44a",
"0x714821f8f257e0a502b71ac7ee57530bb9dc29fe12ff3936f925b835a297680400b76948",
"0x9951e512546cd9c9fbdab348b6cba91a601a29b50854e55a6e14f6803ca1d81ac7eff5ce",
"0xaaa7bacf26f1aa4754d42edeab45d6169ea723b7fdf0f6ff3b6ebe90d09dbff6bc553936",
"0xba75a143de4ac932986fbe7b1d78f639bc6ee8aee10d510d41572851530be884778052aa",
"0xea5315941f4337752905599710b55e64018c71f4d8f299d0636d50484d05e6ac5667b503"
],
"maxBurnedMana": "864"
},
"signature": {
"type": 0,
"publicKey": "0x2daefbcbadd044da470acd2f7fcf6fcb04b873cc801e7ee408018e1dfa0257ac",
"signature": "0x74e57aa62358bb91ee931c05337a3af2e624fa9b20b04fcb4e15da0a9a4b4281a50ef6384ab7977179d16bd326cebb714c4653e1711447f18cefe1066aa1610d"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"blockId": "0xf7ac0552041789a3931ae76eafa47df063632cddd3f8b11bd0bfffba1bc8c46800000000",
"blockState": "confirmed",
"transactionMetadata": {
"transactionId": "0x72f0dfa9ad116ade8bdac8ef291ed2fb8065c6c75d5d3666e8b2053696c94a9e00001000",
"transactionState": "confirmed"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"blockId": "0x3848a6d17070830206e5032fbce2ae3939e60eec0816546e074316b1f66977d04d010000",
"blockState": "confirmed"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"blockId": "0x3848a6d17070830206e5032fbce2ae3939e60eec0816546e074316b1f66977d04d010000",
"blockState": "confirmed",
"transactionMetadata": {
"transactionId": "0x72f0dfa9ad116ade8bdac8ef291ed2fb8065c6c75d5d3666e8b2053696c94a9e00001000",
"transactionState": "failed",
"transactionFailureReason": 2
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"blockId": "0x0482f0eba39a23c9a13072c93d828b55543132c47f5f57514d9e55535e9d4f4f35000000",
"blockState": "pending",
"transactionMetadata": {
"transactionId": "0x72f0dfa9ad116ade8bdac8ef291ed2fb8065c6c75d5d3666e8b2053696c94a9e00001000",
"transactionState": "pending"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"blockId": "0x0482f0eba39a23c9a13072c93d828b55543132c47f5f57514d9e55535e9d4f4f35000000",
"blockState": "pending"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{
"header": {
"protocolVersion": 3,
"networkId": "8342982141227064571",
"issuingTime": "1695275852000000000",
"slotCommitmentId": "0x3a1e3b617060146e0362361a4b752833186108395f3b2b3d3e6c655e287d70767ea58d2a",
"latestFinalizedSlot": 500,
"issuerId": "0x17432c5a7a672503480241125e3952414a7a320441080c624c264b004e09614a"
},
"body": {
"type": 1,
"strongParents": [
"0x27e0461873f37040c9e59c35ad8a106fa1b94f5ec9ef89499b31904f9a3de59be58dd44a",
"0x714821f8f257e0a502b71ac7ee57530bb9dc29fe12ff3936f925b835a297680400b76948",
"0x9951e512546cd9c9fbdab348b6cba91a601a29b50854e55a6e14f6803ca1d81ac7eff5ce",
"0xaaa7bacf26f1aa4754d42edeab45d6169ea723b7fdf0f6ff3b6ebe90d09dbff6bc553936",
"0xba75a143de4ac932986fbe7b1d78f639bc6ee8aee10d510d41572851530be884778052aa",
"0xea5315941f4337752905599710b55e64018c71f4d8f299d0636d50484d05e6ac5667b503"
],
"highestSupportedVersion": 3,
"protocolParametersHash": "0x0c0a5be47669365426b3e34ecd68f8fe6c70656a54139a1e1cd6fd779bfb476f"
},
"signature": {
"type": 0,
"publicKey": "0x2daefbcbadd044da470acd2f7fcf6fcb04b873cc801e7ee408018e1dfa0257ac",
"signature": "0x3b6185bb5757d5e7fd576eeedf0c765c44cbcfe148261b8558a942867528f2cfe5a39a6ecd7bf7e82e134867a75df05385624be8c4102b3b77b397163459460b"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"strongParents": [
"0x0482f0eba39a23c9a13072c93d828b55543132c47f5f57514d9e55535e9d4f4f35000000",
"0xae7c4f55a6db8bf4841e4a38f06d32ab9bd88b927a6ba0bc19bcb19c625ff8b63c000000"
],
"weakParents": [
"0x67e57f7446b5a6f152afabb17c6077c26512278a275310a7ff2fa513f4e0b7383d000000",
"0x2e65c319e9a2c4a6ff7195f9a1ed896c43d0dded1b906979316d502b158965c23d000000"
],
"shallowLikeParents": [
"0xe5fe5231630afaaba609af76787ff1ec9c6088dd17e9cf922152b3facd7bd5883e000000",
"0xed4b771b5413f5118dd80021ca07fb727e4c54eec9d28d6566c28cc81e7d267c3f000000"
],
"latestParentBlockIssuingTime": "1690879505000000000",
"latestFinalizedSlot": 1422,
"latestCommitment": {
"protocolVersion": 3,
"slot": 1432,
"previousCommitmentId": "0xc0300d55fe2cdc93191e52685da009f53d40883ae111291e550eed4e7eb7752746010000",
"rootsId": "0x6a8f424929e1f08d87a204efc8a60499b789465aaa28178b77debe75cc2915d3",
"cumulativeWeight": "45678",
"referenceManaCost": "12345"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
0312000000075b05e0a8fd4b9c7e7bc165b62c48945292f7d76d23f76525f886c416dc0e364089b57c32ddb8c614ed1d2c844401d2a5325b4d153c7f94464bbda3a8d14289b203f96759000000000000009000000000000000
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"protocolVersion": 3,
"slot": 986,
"previousCommitmentId": "0xd91549dbf441da4c7e50063b58c05d5b2bfb1d33b346a2f9a18220ce6207f7a289010000",
"rootsId": "0x6a8f424929e1f08d87a204efc8a60499b789465aaa28178b77debe75cc2915d3",
"cumulativeWeight": "78901",
"referenceManaCost": "600"
}
19 changes: 19 additions & 0 deletions sdk/tests/types/api/fixtures/get-committee-example.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"epoch": 10,
"totalStake": "900000000",
"totalValidatorStake": "60000000",
"committee": [
{
"address": "rms1pqm4xk8e9ny5w5rxjkvtp249tfhlwvcshyr3pc0665jvp7g3hc875k538hl",
"poolStake": "200000",
"validatorStake": "100000",
"fixedCost": "50000"
},
{
"address": "rms1pp4wuuz0y42caz48vv876qfpmffswsvg40zz8v79sy8cp0jfxm4kunflcgt",
"poolStake": "205000",
"validatorStake": "90000",
"fixedCost": "52000"
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"slot": 20,
"ready": true,
"referenceManaCost": "50000",
"blockIssuanceCredits": "10000000"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
{
"block": {
"header": {
"protocolVersion": 3,
"networkId": "8342982141227064571",
"issuingTime": "1695275852000000000",
"slotCommitmentId": "0x3a1e3b617060146e0362361a4b752833186108395f3b2b3d3e6c655e287d70767ea58d2a",
"latestFinalizedSlot": 500,
"issuerId": "0x17432c5a7a672503480241125e3952414a7a320441080c624c264b004e09614a"
},
"body": {
"type": 0,
"strongParents": [
"0x27e0461873f37040c9e59c35ad8a106fa1b94f5ec9ef89499b31904f9a3de59be58dd44a",
"0x714821f8f257e0a502b71ac7ee57530bb9dc29fe12ff3936f925b835a297680400b76948",
"0x9951e512546cd9c9fbdab348b6cba91a601a29b50854e55a6e14f6803ca1d81ac7eff5ce",
"0xaaa7bacf26f1aa4754d42edeab45d6169ea723b7fdf0f6ff3b6ebe90d09dbff6bc553936",
"0xba75a143de4ac932986fbe7b1d78f639bc6ee8aee10d510d41572851530be884778052aa",
"0xea5315941f4337752905599710b55e64018c71f4d8f299d0636d50484d05e6ac5667b503"
],
"payload": {
"type": 0,
"tag": "0x746167",
"data": "0x6c754128356c071e5549764a48427b"
},
"maxBurnedMana": "864"
},
"signature": {
"type": 0,
"publicKey": "0x2daefbcbadd044da470acd2f7fcf6fcb04b873cc801e7ee408018e1dfa0257ac",
"signature": "0xc2982c2476379db0c8d39a204801163fc05dc1c7aa7df537e6041f91491943ab1de29a2dfe6076588c53b8d2ccf5eabe49f2cb64198303682859fd0c58348b0d"
}
},
"metadata": {
"blockId": "0x1d5f495c0f4b883cf2c79cafd382c73484c65651099329e3b0b4c969c35d620004000000",
"blockState": "confirmed"
}
}
40 changes: 40 additions & 0 deletions sdk/tests/types/api/fixtures/get-full-output-metadata-example.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
{
"output": {
"type": 0,
"amount": "1000",
"unlockConditions": [
{
"type": 0,
"address": {
"type": 0,
"pubKeyHash": "0x8eaf87ac1f52eb05f2c7c0c15502df990a228838dc37bd18de9503d69afd257d"
}
}
],
"mana": "2000"
},
"outputIdProof": {
"slot": 1893592032,
"outputIndex": 0,
"transactionCommitment": "0xa0687905318860e64db6932d8423bf7a4418627baee62be8089d5f48aaa1af3a",
"outputCommitmentProof": {
"type": 2,
"hash": "0x7f9289b104a55e6fb93d60d70f6e85c9706c761b05ccc034f76b465837ca6070"
}
},
"metadata": {
"outputId": "0x3130f21c723fa597805763739f3a2a40b674af6b4071ef0494331b644a7e4d52000000001300",
"blockId": "0x19e589687082d8f535779df3244908ad6a7b380906fb7ae24efb5fad8a5cfb92a8f8d9a3",
"included": {
"slot": 5,
"transactionId": "0x3e766157614a3a0e13dbb937b5fb1ef5d1555479c19df80445d03a6710f39d75668bd326",
"commitmentId": "0x7387ebe23a3ac1732fcdb6cef77fc003e1fa6e2dad89dd664df249d6aa2dbdc157dec2c6"
},
"spent": {
"slot": 8,
"transactionId": "0x3896f1ede7cbdacbbb4b17f13e953ad45ce0969ea34cc766b5dafe2a15b3e46f998ef4e5",
"commitmentId": "0x26fa9fcbddcf944ced3fd16a73d9c8b2b49dc54dba7629b02da69f7e01249063e7398b2c"
},
"latestCommitmentId": "0x42a88617c2c4ba2b58f82c8b85524720cdbe3642401e7c613f215658d617c569d1219909"
}
}
Loading