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

Make dry_run return transparent Receipt #702

Merged
merged 21 commits into from
Oct 26, 2022
Merged
Show file tree
Hide file tree
Changes from 15 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
299 changes: 183 additions & 116 deletions Cargo.lock

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ members = [
"xtask",
]

[patch.crates-io]
Salka1988 marked this conversation as resolved.
Show resolved Hide resolved
fuel-vm = { git = "https://github.com/FuelLabs/fuel-vm.git"}

[profile.release]
codegen-units = 1
lto = "fat"
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 @@ -486,6 +486,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,42 @@
---
source: fuel-client/src/client/schema/tx.rs
Salka1988 marked this conversation as resolved.
Show resolved Hide resolved
assertion_line: 324
assertion_line: 339
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
@@ -1,86 +1,14 @@
---
source: fuel-client/src/client/schema/tx.rs
assertion_line: 314
expression: operation.query
---
query Query($_0: TransactionId!) {
transaction(id: $_0) {
gasLimit
gasPrice
id
inputAssetIds
inputContracts {
id
}
inputs {
__typename
... on InputCoin {
utxoId
owner
amount
assetId
txPointer
witnessIndex
maturity
predicate
predicateData
}
... on InputContract {
utxoId
balanceRoot
stateRoot
txPointer
contract {
id
}
}
... on InputMessage {
messageId
sender
recipient
amount
nonce
witnessIndex
data
predicate
predicateData
}
}
isScript
outputs {
__typename
... on CoinOutput {
to
amount
assetId
}
... on ContractOutput {
inputIndex
balanceRoot
stateRoot
}
... on MessageOutput {
recipient
amount
}
... on ChangeOutput {
to
amount
assetId
}
... on VariableOutput {
to
amount
assetId
}
... on ContractCreated {
contract {
id
}
stateRoot
}
rawPayload
Salka1988 marked this conversation as resolved.
Show resolved Hide resolved
receipts {
rawPayload
}
maturity
receiptsRoot
status {
__typename
... on SubmittedStatus {
Expand Down Expand Up @@ -108,46 +36,6 @@ query Query($_0: TransactionId!) {
}
}
}
witnesses
receipts {
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
}
script
scriptData
salt
storageSlots
bytecodeWitnessIndex
bytecodeLength
}
}

9 changes: 4 additions & 5 deletions fuel-client/src/client/schema/tx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ use std::convert::{
TryInto,
};

pub mod transparent_receipt;

#[derive(cynic::FragmentArguments, Debug)]
pub struct TxIdArgs {
pub id: TransactionId,
Expand Down Expand Up @@ -260,7 +262,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>,
xgreenx marked this conversation as resolved.
Show resolved Hide resolved
}

#[derive(cynic::QueryFragment, Debug)]
Expand All @@ -280,13 +282,10 @@ 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;
let operation = transparent_tx::TransactionQuery::build(TxIdArgs {
let operation = TransactionQuery::build(TxIdArgs {
Salka1988 marked this conversation as resolved.
Show resolved Hide resolved
id: TransactionId::default(),
});
insta::assert_snapshot!(operation.query)
Expand Down
6 changes: 4 additions & 2 deletions fuel-client/src/client/schema/tx/tests/transparent_tx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ use crate::client::schema::{
contract::ContractIdFragment,
schema,
tx::{
tests::transparent_receipt::Receipt,
TransactionStatus,
TxIdArgs,
},
Expand All @@ -24,7 +23,10 @@ use core::convert::{
TryFrom,
TryInto,
};
use fuel_vm::fuel_tx::StorageSlot;
use fuel_vm::{
fuel_tx::StorageSlot,
prelude::Receipt,
};
use itertools::Itertools;

/// Retrieves the transaction in opaque form
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
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::{
PredicateStorage,
},
},
state::StateTransition,
},
db::{
Coins,
Expand Down Expand Up @@ -312,13 +313,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
4 changes: 4 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,9 @@ impl Receipt {
async fn nonce(&self) -> Option<Bytes32> {
self.0.nonce().copied().map(Bytes32)
}
async fn contract_id(&self) -> Option<ContractId> {
Salka1988 marked this conversation as resolved.
Show resolved Hide resolved
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 @@ -143,7 +143,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