Skip to content

Commit

Permalink
Make dry_run return transparent Receipt (#702)
Browse files Browse the repository at this point in the history
  • Loading branch information
Salka1988 authored and MujkicA committed Oct 26, 2022
1 parent 2f0c604 commit c23290d
Show file tree
Hide file tree
Showing 12 changed files with 70 additions and 19 deletions.
21 changes: 16 additions & 5 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion fuel-client/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ chrono = { version = "0.4", features = ["serde"] }
clap = { version = "3.1", features = ["derive"] }
cynic = { version = "1.0", features = ["surf"] }
derive_more = { version = "0.99" }
fuel-vm = { version = "0.18", features = ["serde"] }
fuel-vm = { version = "0.19", features = ["serde"] }
futures = "0.3"
futures-timer = "3.0"
hex = "0.4"
Expand Down
1 change: 1 addition & 0 deletions fuel-client/assets/schema.sdl
Original file line number Diff line number Diff line change
Expand Up @@ -485,6 +485,7 @@ type Receipt {
sender: Address
recipient: Address
nonce: Bytes32
contractId: ContractId
}

enum ReceiptType {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,41 @@
---
source: fuel-client/src/client/schema/tx.rs
assertion_line: 324
expression: query.query

---
mutation Mutation($_0: HexString!, $_1: Boolean) {
dryRun(tx: $_0, utxoValidation: $_1) {
rawPayload
param1
param2
amount
assetId
gas
digest
contract {
id
}
is
pc
ptr
ra
rb
rc
rd
reason
receiptType
to {
id
}
toAddress
val
len
result
gasUsed
data
messageId
sender
recipient
nonce
contractId
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ query Query($_0: TransactionId!) {
sender
recipient
nonce
contractId
}
script
scriptData
Expand Down
8 changes: 4 additions & 4 deletions fuel-client/src/client/schema/tx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ use std::convert::{
TryInto,
};

pub mod transparent_receipt;
pub mod transparent_tx;

#[derive(cynic::FragmentArguments, Debug)]
pub struct TxIdArgs {
pub id: TransactionId,
Expand Down Expand Up @@ -260,7 +263,7 @@ pub struct DryRunArg {
)]
pub struct DryRun {
#[arguments(tx = &args.tx, utxo_validation = &args.utxo_validation)]
pub dry_run: Vec<OpaqueReceipt>,
pub dry_run: Vec<transparent_receipt::Receipt>,
}

#[derive(cynic::QueryFragment, Debug)]
Expand All @@ -280,9 +283,6 @@ pub mod tests {
use crate::client::schema::Bytes;
use fuel_vm::fuel_types::bytes::SerializableVec;

pub mod transparent_receipt;
pub mod transparent_tx;

#[test]
fn transparent_transaction_by_id_query_gql_output() {
use cynic::QueryBuilder;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use crate::client::schema::{
Address,
AssetId,
Bytes32,
ContractId,
ConversionError,
ConversionError::MissingField,
HexString,
Expand Down Expand Up @@ -42,6 +43,7 @@ pub struct Receipt {
pub sender: Option<Address>,
pub recipient: Option<Address>,
pub nonce: Option<Bytes32>,
pub contract_id: Option<ContractId>,
}

#[derive(cynic::Enum, Clone, Copy, Debug)]
Expand Down Expand Up @@ -173,6 +175,7 @@ impl TryFrom<Receipt> for fuel_vm::prelude::Receipt {
.is
.ok_or_else(|| MissingField("is".to_string()))?
.into(),
contract_id: schema.contract_id.map(Into::into),
},
ReceiptType::Revert => fuel_vm::prelude::Receipt::Revert {
id: schema
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use crate::client::schema::{
contract::ContractIdFragment,
schema,
tx::{
tests::transparent_receipt::Receipt,
transparent_receipt::Receipt,
TransactionStatus,
TxIdArgs,
},
Expand Down
2 changes: 1 addition & 1 deletion fuel-core-interfaces/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ anyhow = "1.0"
async-trait = "0.1"
chrono = { version = "0.4" }
derive_more = { version = "0.99" }
fuel-vm = { version = "0.18", default-features = false, features = ["random"] }
fuel-vm = { version = "0.19", default-features = false, features = ["random"] }
futures = "0.3"
lazy_static = "1.4"
parking_lot = "0.12"
Expand Down
5 changes: 3 additions & 2 deletions fuel-core/src/executor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ use fuel_core_interfaces::{
},
},
prelude::StorageInspect,
state::StateTransition,
},
db::{
Coins,
Expand Down Expand Up @@ -315,13 +316,13 @@ impl Executor {
sub_db_view.clone(),
self.config.chain_conf.transaction_parameters,
);
let vm_result = vm
let vm_result: StateTransition = vm
.transact(checked_tx)
.map_err(|error| Error::VmExecution {
error,
transaction_id: tx_id,
})?
.into_owned();
.into();

// only commit state changes if execution was a success
if !vm_result.should_revert() {
Expand Down
5 changes: 5 additions & 0 deletions fuel-core/src/schema/tx/receipt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use crate::schema::{
Address,
AssetId,
Bytes32,
ContractId,
HexString,
MessageId,
U64,
Expand Down Expand Up @@ -141,6 +142,10 @@ impl Receipt {
async fn nonce(&self) -> Option<Bytes32> {
self.0.nonce().copied().map(Bytes32)
}

async fn contract_id(&self) -> Option<ContractId> {
self.0.contract_id().map(|id| ContractId(*id))
}
}

impl From<&fuel_tx::Receipt> for Receipt {
Expand Down
4 changes: 2 additions & 2 deletions fuel-tests/tests/tx/utxo_validation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ async fn submit_utxo_verified_tx_with_min_gas_price() {
Opcode::RET(REG_ONE).to_bytes().into_iter().collect(),
vec![],
)
.gas_limit(100)
.gas_limit(10000)
.gas_price(1)
.add_unsigned_coin_input(
SecretKey::random(&mut rng),
Expand Down Expand Up @@ -144,7 +144,7 @@ async fn dry_run_override_utxo_validation() {
Opcode::RET(REG_ONE).to_bytes().into_iter().collect(),
vec![],
)
.gas_limit(1000)
.gas_limit(10000)
.add_input(Input::coin_signed(
rng.gen(),
rng.gen(),
Expand Down

0 comments on commit c23290d

Please sign in to comment.