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

Fixed wrong encoding of the Mint and Burn receipts. #1264

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

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions crates/client/assets/schema.sdl
Original file line number Diff line number Diff line change
Expand Up @@ -650,6 +650,10 @@ type Query {
"""
estimatePredicates(tx: HexString!): Transaction!
"""
Returns all possible receipts for test purposes.
"""
allReceipts: [Receipt!]!
"""
Returns true when the GraphQL API is serving requests.
"""
health: Boolean!
Expand Down
13 changes: 13 additions & 0 deletions crates/client/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -648,6 +648,19 @@ impl FuelClient {
Ok(receipts)
}

#[cfg(feature = "test-helpers")]
pub async fn all_receipts(&self) -> io::Result<Vec<Receipt>> {
let query = schema::tx::AllReceipts::build(());
let receipts = self.query(query).await?.all_receipts;

let vec: Result<Vec<Receipt>, ConversionError> = receipts
.into_iter()
.map(TryInto::<Receipt>::try_into)
.collect();

Ok(vec?)
}

pub async fn produce_blocks(
&self,
blocks_to_produce: u64,
Expand Down
8 changes: 7 additions & 1 deletion crates/client/src/client/schema/tx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ pub struct DryRunArg {
)]
pub struct DryRun {
#[arguments(tx: $tx, utxoValidation: $utxo_validation)]
pub dry_run: Vec<transparent_receipt::Receipt>,
pub dry_run: Vec<Receipt>,
}

#[derive(cynic::QueryFragment, Debug)]
Expand All @@ -309,6 +309,12 @@ pub struct SubmitAndAwaitSubscription {
pub submit_and_await: TransactionStatus,
}

#[derive(cynic::QueryFragment, Debug)]
#[cynic(schema_path = "./assets/schema.sdl", graphql_type = "Query")]
pub struct AllReceipts {
pub all_receipts: Vec<Receipt>,
}

#[cfg(test)]
pub mod tests {
use super::*;
Expand Down
10 changes: 2 additions & 8 deletions crates/client/src/client/schema/tx/transparent_receipt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -343,10 +343,7 @@ impl TryFrom<Receipt> for fuel_tx::Receipt {
.sub_id
.ok_or_else(|| MissingField("sub_id".to_string()))?
.into(),
contract_id: schema
.contract_id
.ok_or_else(|| MissingField("contract_id".to_string()))?
.into(),
contract_id: schema.contract.map(|id| id.id.into()).unwrap_or_default(),
val: schema
.val
.ok_or_else(|| MissingField("val".to_string()))?
Expand All @@ -365,10 +362,7 @@ impl TryFrom<Receipt> for fuel_tx::Receipt {
.sub_id
.ok_or_else(|| MissingField("sub_id".to_string()))?
.into(),
contract_id: schema
.contract_id
.ok_or_else(|| MissingField("contract_id".to_string()))?
.into(),
contract_id: schema.contract.map(|id| id.id.into()).unwrap_or_default(),
val: schema
.val
.ok_or_else(|| MissingField("val".to_string()))?
Expand Down
9 changes: 9 additions & 0 deletions crates/fuel-core/src/schema/tx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,15 @@ impl TxQuery {
tx,
))
}

#[cfg(feature = "test-helpers")]
/// Returns all possible receipts for test purposes.
async fn all_receipts(&self) -> Vec<receipt::Receipt> {
receipt::all_receipts()
.into_iter()
.map(Into::into)
.collect()
}
}

#[derive(Default)]
Expand Down
108 changes: 107 additions & 1 deletion crates/fuel-core/src/schema/tx/receipt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ use fuel_core_types::{
fuel_tx,
};

#[derive(Copy, Clone, Debug, Display, Enum, Eq, PartialEq)]
#[derive(Copy, Clone, Debug, Display, Enum, Eq, PartialEq, strum_macros::EnumIter)]
pub enum ReceiptType {
Call,
Return,
Expand Down Expand Up @@ -158,3 +158,109 @@ impl From<fuel_tx::Receipt> for Receipt {
Receipt(receipt)
}
}

#[cfg(feature = "test-helpers")]
pub fn all_receipts() -> Vec<fuel_tx::Receipt> {
use strum::IntoEnumIterator;

let mut receipts = vec![];
for variant in ReceiptType::iter() {
let receipt = match variant {
ReceiptType::Call => fuel_tx::Receipt::call(
fuel_tx::ContractId::from([1u8; 32]),
fuel_tx::ContractId::from([2u8; 32]),
3,
fuel_tx::AssetId::from([3u8; 32]),
5,
6,
7,
8,
9,
),
ReceiptType::Return => {
fuel_tx::Receipt::ret(fuel_tx::ContractId::from([1u8; 32]), 2, 3, 4)
}
ReceiptType::ReturnData => fuel_tx::Receipt::return_data(
fuel_tx::ContractId::from([1u8; 32]),
2,
3,
4,
vec![5; 30],
),
ReceiptType::Panic => fuel_tx::Receipt::panic(
fuel_tx::ContractId::from([1u8; 32]),
fuel_core_types::fuel_asm::PanicInstruction::error(
fuel_core_types::fuel_asm::PanicReason::ArithmeticOverflow,
2,
),
3,
4,
),
ReceiptType::Revert => {
fuel_tx::Receipt::revert(fuel_tx::ContractId::from([1u8; 32]), 2, 3, 4)
}
ReceiptType::Log => fuel_tx::Receipt::log(
fuel_tx::ContractId::from([1u8; 32]),
2,
3,
4,
5,
6,
7,
),
ReceiptType::LogData => fuel_tx::Receipt::log_data(
fuel_tx::ContractId::from([1u8; 32]),
2,
3,
4,
5,
6,
vec![7; 30],
),
ReceiptType::Transfer => fuel_tx::Receipt::transfer(
fuel_tx::ContractId::from([1u8; 32]),
fuel_tx::ContractId::from([2u8; 32]),
3,
fuel_tx::AssetId::from([4u8; 32]),
5,
6,
),
ReceiptType::TransferOut => fuel_tx::Receipt::transfer_out(
fuel_tx::ContractId::from([1u8; 32]),
fuel_tx::Address::from([2u8; 32]),
3,
fuel_tx::AssetId::from([4u8; 32]),
5,
6,
),
ReceiptType::ScriptResult => fuel_tx::Receipt::script_result(
fuel_tx::ScriptExecutionResult::Success,
1,
),
ReceiptType::MessageOut => fuel_tx::Receipt::message_out(
&Default::default(),
1,
fuel_tx::Address::from([2u8; 32]),
fuel_tx::Address::from([3u8; 32]),
4,
vec![5; 30],
),
ReceiptType::Mint => fuel_tx::Receipt::mint(
fuel_tx::Bytes32::from([1u8; 32]),
fuel_tx::ContractId::from([2u8; 32]),
3,
4,
5,
),
ReceiptType::Burn => fuel_tx::Receipt::burn(
fuel_tx::Bytes32::from([1u8; 32]),
fuel_tx::ContractId::from([2u8; 32]),
3,
4,
5,
),
};
receipts.push(receipt);
}
receipts
}
10 changes: 10 additions & 0 deletions tests/tests/tx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use crate::helpers::TestContext;
use fuel_core::{
database::Database,
executor::Executor,
schema::tx::receipt::all_receipts,
service::{
adapters::MaybeRelayerAdapter,
Config,
Expand Down Expand Up @@ -210,6 +211,15 @@ async fn receipts() {
assert!(receipts.is_some());
}

#[tokio::test]
async fn receipts_decoding() {
let srv = FuelService::new_node(Config::local_node()).await.unwrap();
let client = FuelClient::from(srv.bound_address);

let actual_receipts = client.all_receipts().await.unwrap();
assert_eq!(actual_receipts, all_receipts())
}

#[tokio::test]
async fn get_transaction_by_id() {
// setup test data in the node
Expand Down
2 changes: 1 addition & 1 deletion xtask/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ publish = false

[dependencies]
clap = { workspace = true, features = ["env", "derive"] }
fuel-core = { path = "../crates/fuel-core", default-features = false, features = ["dap"] }
fuel-core = { path = "../crates/fuel-core", default-features = false, features = ["dap", "test-helpers"] }

[features]
default = ["fuel-core/default"]