From 0f4438ab31e03bc1587991923ce6ac50de591b74 Mon Sep 17 00:00:00 2001 From: Brandon Kite Date: Tue, 9 Aug 2022 16:12:21 -0700 Subject: [PATCH 1/6] update to latest fuel-tx and vm --- Cargo.lock | 237 +++--------------- fuel-client/Cargo.toml | 4 +- fuel-client/assets/schema.sdl | 4 + fuel-client/src/client/schema/primitives.rs | 24 ++ .../client/schema/tx/tests/transparent_tx.rs | 7 +- fuel-core-interfaces/Cargo.toml | 10 +- fuel-core-interfaces/src/db.rs | 7 + fuel-core/src/database.rs | 5 + fuel-core/src/executor.rs | 12 +- fuel-core/src/schema/scalars.rs | 66 +---- fuel-core/src/schema/scalars/tx_pointer.rs | 67 +++++ fuel-core/src/schema/scalars/utxo_id.rs | 67 +++++ fuel-core/src/schema/tx/input.rs | 17 ++ fuel-tests/Cargo.toml | 2 +- fuel-tests/tests/balances.rs | 1 + fuel-tests/tests/tx.rs | 1 + fuel-tests/tests/tx/predicates.rs | 3 + fuel-tests/tests/tx/utxo_validation.rs | 7 + fuel-txpool/src/containers/dependency.rs | 1 + 19 files changed, 276 insertions(+), 266 deletions(-) create mode 100644 fuel-core/src/schema/scalars/tx_pointer.rs create mode 100644 fuel-core/src/schema/scalars/utxo_id.rs diff --git a/Cargo.lock b/Cargo.lock index b26ab8a0e75..17264010ba9 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -504,7 +504,7 @@ version = "0.5.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b88d82667eca772c4aa12f0f1348b3ae643424c8876448f3f7bd5787032e234c" dependencies = [ - "autocfg 1.1.0", + "autocfg", ] [[package]] @@ -536,15 +536,6 @@ dependencies = [ "syn", ] -[[package]] -name = "autocfg" -version = "0.1.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0dde43e75fd43e8a1bf86103336bc699aa8d17ad1be60c76c0bdfd4828e19b78" -dependencies = [ - "autocfg 1.1.0", -] - [[package]] name = "autocfg" version = "1.1.0" @@ -718,7 +709,7 @@ version = "0.7.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c0940dc441f31689269e10ac70eb1002a3a1d3ad1390e030043662eb7fe4688b" dependencies = [ - "block-padding 0.1.5", + "block-padding", "byte-tools", "byteorder", "generic-array 0.12.4", @@ -730,7 +721,6 @@ version = "0.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4152116fd6e9dadb291ae18fc1ec3575ed6d84c29642d97890f4b4a3417297e4" dependencies = [ - "block-padding 0.2.1", "generic-array 0.14.5", ] @@ -752,12 +742,6 @@ dependencies = [ "byte-tools", ] -[[package]] -name = "block-padding" -version = "0.2.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8d696c370c750c948ada61c69a0ee2cbbb9c50b1019ddb86d9317157a99c2cae" - [[package]] name = "blocking" version = "1.2.0" @@ -1018,15 +1002,6 @@ dependencies = [ "os_str_bytes", ] -[[package]] -name = "cloudabi" -version = "0.0.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ddfc5b9aa5d4507acaf872de71051dfd0e309860e88966e1051e462a077aac4f" -dependencies = [ - "bitflags", -] - [[package]] name = "coins-bip32" version = "0.7.0" @@ -1080,7 +1055,7 @@ dependencies = [ "serde", "serde_derive", "sha2 0.10.2", - "sha3 0.10.1", + "sha3", "thiserror", ] @@ -1712,7 +1687,7 @@ dependencies = [ "serde", "serde_json", "sha2 0.10.2", - "sha3 0.10.1", + "sha3", "thiserror", "uuid", ] @@ -1729,7 +1704,7 @@ dependencies = [ "regex", "serde", "serde_json", - "sha3 0.10.1", + "sha3", "thiserror", "uint", ] @@ -2082,17 +2057,11 @@ version = "1.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2022715d62ab30faffd124d40b76f4134a550a87792276512b18d63272333394" -[[package]] -name = "fuchsia-cprng" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a06f77d526c1a601b7c4cdd98f54b5eaabffc14d5f2f0296febdc7f357c6d3ba" - [[package]] name = "fuel-asm" -version = "0.6.0" +version = "0.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cf02de44ec38d5977d61896cd228b45c9596a38f940f964cacb2d683ada6a064" +checksum = "135ef9990debd1fa257988a0a8be5b9d787decaba911cc3b97d7712a4b70328d" dependencies = [ "fuel-types", "serde", @@ -2197,7 +2166,7 @@ dependencies = [ "fuel-asm", "fuel-crypto", "fuel-merkle", - "fuel-storage 0.1.0", + "fuel-storage", "fuel-tx", "fuel-types", "fuel-vm", @@ -2211,17 +2180,19 @@ dependencies = [ [[package]] name = "fuel-crypto" -version = "0.5.0" +version = "0.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8af1477833b63cf956b71a63a67a7af0e7477bd2f774536556fe0338f909542e" +checksum = "c27380c9c0a97da57123eb981289431069371cc71439f8d0192b604c1414f705" dependencies = [ "borrown", + "coins-bip32", + "coins-bip39", "fuel-types", "lazy_static", "rand 0.8.5", "secp256k1", "serde", - "sha2 0.9.9", + "sha2 0.10.2", ] [[package]] @@ -2254,7 +2225,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1fa59f2a4e6cd6d83a51981c5ac706d58fc8ef53700003948c826827b88cfff1" dependencies = [ "digest 0.10.3", - "fuel-storage 0.2.0", + "fuel-storage", "hashbrown", "hex", "sha2 0.10.2", @@ -2306,7 +2277,7 @@ dependencies = [ "rand 0.8.5", "serde", "serde_json", - "sha3 0.10.1", + "sha3", "thiserror", "tokio", "tracing", @@ -2315,12 +2286,6 @@ dependencies = [ "url", ] -[[package]] -name = "fuel-storage" -version = "0.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f97a6a68c3378e486d645a47026bcd7139500345ef214653811ea4f016f142ce" - [[package]] name = "fuel-storage" version = "0.2.0" @@ -2361,9 +2326,9 @@ dependencies = [ [[package]] name = "fuel-tx" -version = "0.16.1" +version = "0.18.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2cd230b9907fce301cff8304f80e272d825a426003762b2efd9672fdd3fa5d26" +checksum = "118b773c25dbf645457fbd9b0288ac923c044d03ce68f492e539c840c3595f5e" dependencies = [ "fuel-asm", "fuel-crypto", @@ -2402,22 +2367,23 @@ dependencies = [ [[package]] name = "fuel-vm" -version = "0.13.0" +version = "0.15.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a6250bf62faa0cc69e60e30d27f451c00612f5239453f151251fe8a8935f7bb4" +checksum = "516d60fc504570c0ad79f6dffcbd31687b15b76ecf8753bccaeae201baac29d2" dependencies = [ "anyhow", "fuel-asm", "fuel-crypto", "fuel-merkle", - "fuel-storage 0.1.0", + "fuel-storage", "fuel-tx", "fuel-types", "itertools", "rand 0.8.5", "secp256k1", "serde", - "sha3 0.9.1", + "sha3", + "tai64", "thiserror", "tracing", ] @@ -3028,7 +2994,7 @@ version = "1.9.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "10a35a97730320ffe8e2d410b5d3b69279b98d2c14bdb8b70ea89ecf7888d41e" dependencies = [ - "autocfg 1.1.0", + "autocfg", "hashbrown", "serde", ] @@ -3143,7 +3109,7 @@ dependencies = [ "ecdsa", "elliptic-curve", "sha2 0.10.2", - "sha3 0.10.1", + "sha3", ] [[package]] @@ -3634,7 +3600,7 @@ version = "0.4.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "327fa5b6a6940e4699ec49a9beae1ea4845c6bab9314e4f84ac68742139d8c53" dependencies = [ - "autocfg 1.1.0", + "autocfg", "scopeguard", ] @@ -3935,7 +3901,7 @@ version = "0.1.45" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "225d3389fb3509a24c93f5c29eb6bde2586b98d9f016636dff58d7c6f7569cd9" dependencies = [ - "autocfg 1.1.0", + "autocfg", "num-traits", ] @@ -3945,7 +3911,7 @@ version = "0.2.15" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "578ede34cf02f8924ab9447f50c28075b4d3e5b269972345e7e0372b38c6cdcd" dependencies = [ - "autocfg 1.1.0", + "autocfg", ] [[package]] @@ -4545,25 +4511,6 @@ version = "0.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "dc33ff2d4973d518d823d61aa239014831e521c75da58e3df4840d3f47749d09" -[[package]] -name = "rand" -version = "0.6.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6d71dacdc3c88c1fde3885a3be3fbab9f35724e6ce99467f7d9c5026132184ca" -dependencies = [ - "autocfg 0.1.8", - "libc", - "rand_chacha 0.1.1", - "rand_core 0.4.2", - "rand_hc 0.1.0", - "rand_isaac", - "rand_jitter", - "rand_os", - "rand_pcg", - "rand_xorshift", - "winapi", -] - [[package]] name = "rand" version = "0.7.3" @@ -4574,7 +4521,7 @@ dependencies = [ "libc", "rand_chacha 0.2.2", "rand_core 0.5.1", - "rand_hc 0.2.0", + "rand_hc", ] [[package]] @@ -4588,16 +4535,6 @@ dependencies = [ "rand_core 0.6.3", ] -[[package]] -name = "rand_chacha" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "556d3a1ca6600bfcbab7c7c91ccb085ac7fbbcd70e008a98742e7847f4f7bcef" -dependencies = [ - "autocfg 0.1.8", - "rand_core 0.3.1", -] - [[package]] name = "rand_chacha" version = "0.2.2" @@ -4618,21 +4555,6 @@ dependencies = [ "rand_core 0.6.3", ] -[[package]] -name = "rand_core" -version = "0.3.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7a6fdeb83b075e8266dcc8762c22776f6877a63111121f5f8c7411e5be7eed4b" -dependencies = [ - "rand_core 0.4.2", -] - -[[package]] -name = "rand_core" -version = "0.4.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9c33a3c44ca05fa6f1807d8e6743f3824e8509beca625669633be0acbdf509dc" - [[package]] name = "rand_core" version = "0.5.1" @@ -4651,15 +4573,6 @@ dependencies = [ "getrandom 0.2.7", ] -[[package]] -name = "rand_hc" -version = "0.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7b40677c7be09ae76218dc623efbf7b18e34bced3f38883af07bb75630a21bc4" -dependencies = [ - "rand_core 0.3.1", -] - [[package]] name = "rand_hc" version = "0.2.0" @@ -4669,68 +4582,6 @@ dependencies = [ "rand_core 0.5.1", ] -[[package]] -name = "rand_isaac" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ded997c9d5f13925be2a6fd7e66bf1872597f759fd9dd93513dd7e92e5a5ee08" -dependencies = [ - "rand_core 0.3.1", -] - -[[package]] -name = "rand_jitter" -version = "0.1.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1166d5c91dc97b88d1decc3285bb0a99ed84b05cfd0bc2341bdf2d43fc41e39b" -dependencies = [ - "libc", - "rand_core 0.4.2", - "winapi", -] - -[[package]] -name = "rand_os" -version = "0.1.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7b75f676a1e053fc562eafbb47838d67c84801e38fc1ba459e8f180deabd5071" -dependencies = [ - "cloudabi", - "fuchsia-cprng", - "libc", - "rand_core 0.4.2", - "rdrand", - "winapi", -] - -[[package]] -name = "rand_pcg" -version = "0.1.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "abf9b09b01790cfe0364f52bf32995ea3c39f4d2dd011eac241d2914146d0b44" -dependencies = [ - "autocfg 0.1.8", - "rand_core 0.4.2", -] - -[[package]] -name = "rand_xorshift" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cbf7e9e623549b0e21f6e97cf8ecf247c1a8fd2e8a992ae265314300b2455d5c" -dependencies = [ - "rand_core 0.3.1", -] - -[[package]] -name = "rdrand" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "678054eb77286b51581ba43620cc911abf02758c91f93f479767aed0f90458b2" -dependencies = [ - "rand_core 0.3.1", -] - [[package]] name = "redox_syscall" version = "0.2.16" @@ -5139,19 +4990,19 @@ dependencies = [ [[package]] name = "secp256k1" -version = "0.20.3" +version = "0.24.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "97d03ceae636d0fed5bae6a7f4f664354c5f4fcedf6eef053fef17e49f837d0a" +checksum = "b7649a0b3ffb32636e60c7ce0d70511eda9c52c658cd0634e194d5a19943aeff" dependencies = [ - "rand 0.6.5", + "rand 0.8.5", "secp256k1-sys", ] [[package]] name = "secp256k1-sys" -version = "0.4.2" +version = "0.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "957da2573cde917463ece3570eab4a0b3f19de6f1646cde62e6fd3868f566036" +checksum = "7058dc8eaf3f2810d7828680320acda0b25a288f6d288e19278e249bbf74226b" dependencies = [ "cc", ] @@ -5359,18 +5210,6 @@ dependencies = [ "digest 0.10.3", ] -[[package]] -name = "sha3" -version = "0.9.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f81199417d4e5de3f04b1e871023acea7389672c4135918f05aa9cbf2f2fa809" -dependencies = [ - "block-buffer 0.9.0", - "digest 0.9.0", - "keccak", - "opaque-debug 0.3.0", -] - [[package]] name = "sha3" version = "0.10.1" @@ -5452,7 +5291,7 @@ version = "0.4.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4614a76b2a8be0058caa9dbbaf66d988527d86d003c11a94fbd335d7661edcef" dependencies = [ - "autocfg 1.1.0", + "autocfg", ] [[package]] @@ -5720,6 +5559,12 @@ dependencies = [ "libc", ] +[[package]] +name = "tai64" +version = "4.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ed7401421025f4132e6c1f7af5e7f8287383969f36e6628016cd509b8d3da9dc" + [[package]] name = "tap" version = "1.0.1" @@ -5895,7 +5740,7 @@ version = "1.20.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7a8325f63a7d4774dd041e363b2409ed1c5cbbd0f867795e661df066b2b0a581" dependencies = [ - "autocfg 1.1.0", + "autocfg", "bytes", "libc", "memchr", diff --git a/fuel-client/Cargo.toml b/fuel-client/Cargo.toml index c0c313e2122..e86c0fa1ab3 100644 --- a/fuel-client/Cargo.toml +++ b/fuel-client/Cargo.toml @@ -20,9 +20,9 @@ chrono = { version = "0.4", features = ["serde"] } clap = { version = "3.1", features = ["derive"] } cynic = { version = "1.0", features = ["surf"] } derive_more = { version = "0.99" } -fuel-tx = { version = "0.16", features = ["serde"] } +fuel-tx = { version = "0.18", features = ["serde"] } fuel-types = { version = "0.5", features = ["serde"] } -fuel-vm = { version = "0.13", features = ["serde"] } +fuel-vm = { version = "0.15", features = ["serde"] } futures = "0.3" hex = "0.4" itertools = "0.10" diff --git a/fuel-client/assets/schema.sdl b/fuel-client/assets/schema.sdl index 3616dd4a95b..d2591b7cb28 100644 --- a/fuel-client/assets/schema.sdl +++ b/fuel-client/assets/schema.sdl @@ -268,6 +268,7 @@ type InputCoin { owner: Address! amount: U64! assetId: AssetId! + txPointer: TxPointer! witnessIndex: Int! maturity: U64! predicate: HexString! @@ -278,6 +279,7 @@ type InputContract { utxoId: UtxoId! balanceRoot: Bytes32! stateRoot: Bytes32! + txPointer: TxPointer! contract: Contract! } @@ -587,6 +589,8 @@ scalar TransactionId union TransactionStatus = SubmittedStatus | SuccessStatus | FailureStatus +scalar TxPointer + scalar U64 scalar UtxoId diff --git a/fuel-client/src/client/schema/primitives.rs b/fuel-client/src/client/schema/primitives.rs index ff4806ad79d..bfc9c50bdb3 100644 --- a/fuel-client/src/client/schema/primitives.rs +++ b/fuel-client/src/client/schema/primitives.rs @@ -119,6 +119,30 @@ impl LowerHex for UtxoId { } } +#[derive(cynic::Scalar, Debug, Clone, Default)] +pub struct TxPointer(pub HexFormatted); + +impl FromStr for TxPointer { + type Err = ConversionError; + + fn from_str(s: &str) -> Result { + let b = HexFormatted::::from_str(s)?; + Ok(TxPointer(b)) + } +} + +impl From for fuel_tx::TxPointer { + fn from(s: TxPointer) -> Self { + s.0 .0 + } +} + +impl LowerHex for TxPointer { + fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { + LowerHex::fmt(&self.0 .0, f) + } +} + #[derive(cynic::Scalar, Debug, Clone)] pub struct HexString(pub Bytes); diff --git a/fuel-client/src/client/schema/tx/tests/transparent_tx.rs b/fuel-client/src/client/schema/tx/tests/transparent_tx.rs index c67f97d8490..6607cc74efe 100644 --- a/fuel-client/src/client/schema/tx/tests/transparent_tx.rs +++ b/fuel-client/src/client/schema/tx/tests/transparent_tx.rs @@ -3,7 +3,7 @@ use crate::client::schema::{ schema, tx::{tests::transparent_receipt::Receipt, TransactionStatus, TxIdArgs}, Address, AssetId, Bytes32, ConnectionArgs, ConversionError, HexString, MessageId, PageInfo, - Salt, TransactionId, UtxoId, U64, + Salt, TransactionId, TxPointer, UtxoId, U64, }; use core::convert::{TryFrom, TryInto}; use fuel_tx::StorageSlot; @@ -173,6 +173,7 @@ pub struct InputCoin { pub owner: Address, pub amount: U64, pub asset_id: AssetId, + pub tx_pointer: TxPointer, pub witness_index: i32, pub maturity: U64, pub predicate: HexString, @@ -185,6 +186,7 @@ pub struct InputContract { pub utxo_id: UtxoId, pub balance_root: Bytes32, pub state_root: Bytes32, + pub tx_pointer: TxPointer, pub contract: ContractIdFragment, } @@ -215,6 +217,7 @@ impl TryFrom for fuel_tx::Input { owner: coin.owner.into(), amount: coin.amount.into(), asset_id: coin.asset_id.into(), + tx_pointer: coin.tx_pointer.into(), witness_index: coin.witness_index.try_into()?, maturity: coin.maturity.into(), } @@ -225,6 +228,7 @@ impl TryFrom for fuel_tx::Input { amount: coin.amount.into(), asset_id: coin.asset_id.into(), maturity: coin.maturity.into(), + tx_pointer: coin.tx_pointer.into(), predicate: coin.predicate.into(), predicate_data: coin.predicate_data.into(), } @@ -234,6 +238,7 @@ impl TryFrom for fuel_tx::Input { utxo_id: contract.utxo_id.into(), balance_root: contract.balance_root.into(), state_root: contract.state_root.into(), + tx_pointer: contract.tx_pointer.into(), contract_id: contract.contract.id.into(), }, Input::InputMessage(message) => { diff --git a/fuel-core-interfaces/Cargo.toml b/fuel-core-interfaces/Cargo.toml index d15f48ebcb3..1cf4e9f1d81 100644 --- a/fuel-core-interfaces/Cargo.toml +++ b/fuel-core-interfaces/Cargo.toml @@ -15,13 +15,13 @@ anyhow = "1.0" async-trait = "0.1" chrono = { version = "0.4" } derive_more = { version = "0.99" } -fuel-asm = "0.6" -fuel-crypto = { version = "0.5", default-features = false, features = [ "random" ] } +fuel-asm = "0.8" +fuel-crypto = { version = "0.6", default-features = false, features = [ "random" ] } fuel-merkle = { version = "0.3" } -fuel-storage = "0.1" -fuel-tx = { version = "0.16", default-features = false } +fuel-storage = "0.2" +fuel-tx = { version = "0.18", default-features = false } fuel-types = { version = "0.5", default-features = false } -fuel-vm = { version = "0.13", default-features = false } +fuel-vm = { version = "0.15", default-features = false } futures = "0.3" lazy_static = "1.4" parking_lot = "0.12" diff --git a/fuel-core-interfaces/src/db.rs b/fuel-core-interfaces/src/db.rs index 92850e55bcb..b8fa99ea719 100644 --- a/fuel-core-interfaces/src/db.rs +++ b/fuel-core-interfaces/src/db.rs @@ -203,6 +203,7 @@ pub mod helpers { owner: Address::default(), amount: 100, asset_id: Default::default(), + tx_pointer: Default::default(), witness_index: 0, maturity: 0, }], @@ -241,6 +242,7 @@ pub mod helpers { owner: Address::default(), amount: 100, asset_id: Default::default(), + tx_pointer: Default::default(), witness_index: 0, maturity: 0, }], @@ -272,6 +274,7 @@ pub mod helpers { owner: Address::default(), amount: 100, asset_id: Default::default(), + tx_pointer: Default::default(), witness_index: 0, maturity: 0, }], @@ -304,6 +307,7 @@ pub mod helpers { owner: Address::default(), amount: 100, asset_id: Default::default(), + tx_pointer: Default::default(), witness_index: 0, maturity: 0, }], @@ -343,6 +347,7 @@ pub mod helpers { owner: Address::default(), amount: 100, asset_id: Default::default(), + tx_pointer: Default::default(), witness_index: 0, maturity: 0, }], @@ -376,6 +381,7 @@ pub mod helpers { owner: Address::default(), amount: 200, asset_id: Default::default(), + tx_pointer: Default::default(), witness_index: 0, maturity: 0, }], @@ -407,6 +413,7 @@ pub mod helpers { utxo_id: UtxoId::default(), balance_root: Bytes32::default(), state_root: Bytes32::default(), + tx_pointer: Default::default(), contract_id: *CONTRACT_ID1, }], outputs: vec![ diff --git a/fuel-core/src/database.rs b/fuel-core/src/database.rs index 91d03a08439..567a15c6fb3 100644 --- a/fuel-core/src/database.rs +++ b/fuel-core/src/database.rs @@ -8,6 +8,7 @@ use crate::state::{ in_memory::memory_store::MemoryStore, ColumnId, DataSource, Error, IterDirection, }; use async_trait::async_trait; +use fuel_core_interfaces::common::fuel_asm::Word; pub use fuel_core_interfaces::db::KvStoreError; use fuel_core_interfaces::{ common::{ @@ -261,6 +262,10 @@ impl InterpreterStorage for Database { Ok(height.into()) } + fn timestamp(&self, height: u32) -> Result { + todo!() + } + fn block_hash(&self, block_height: u32) -> Result { let hash = self.get_block_id(block_height.into())?.unwrap_or_default(); Ok(hash) diff --git a/fuel-core/src/executor.rs b/fuel-core/src/executor.rs index 03d02e9c6e6..a37b24182ee 100644 --- a/fuel-core/src/executor.rs +++ b/fuel-core/src/executor.rs @@ -1032,7 +1032,15 @@ mod tests { Storage::::insert(&mut db, &spent_utxo_id, &coin).unwrap(); // create an input referring to a coin that is already spent - let input = Input::coin_signed(spent_utxo_id, owner, amount, asset_id, 0, 0); + let input = Input::coin_signed( + spent_utxo_id, + owner, + amount, + asset_id, + Default::default(), + 0, + 0, + ); let output = Output::Change { to: owner, amount: 0, @@ -1103,6 +1111,7 @@ mod tests { rng.gen(), 10, Default::default(), + Default::default(), 0, ) .add_output(Output::Change { @@ -1325,6 +1334,7 @@ mod tests { rng.gen(), 100, Default::default(), + Default::default(), 0, ) .add_output(Output::Change { diff --git a/fuel-core/src/schema/scalars.rs b/fuel-core/src/schema/scalars.rs index c70b3a06382..42aca0008af 100644 --- a/fuel-core/src/schema/scalars.rs +++ b/fuel-core/src/schema/scalars.rs @@ -3,12 +3,17 @@ use crate::model::BlockHeight; use async_graphql::{ connection::CursorType, InputValueError, InputValueResult, Scalar, ScalarType, Value, }; -use fuel_core_interfaces::common::{fuel_tx, fuel_types}; +use fuel_core_interfaces::common::fuel_types; use std::{ convert::TryInto, fmt::{Display, Formatter}, str::FromStr, }; +pub use tx_pointer::TxPointer; +pub use utxo_id::UtxoId; + +pub mod tx_pointer; +pub mod utxo_id; /// Need our own u64 type since GraphQL integers are restricted to i32. #[derive(Copy, Clone, Debug, derive_more::Into, derive_more::From)] @@ -136,65 +141,6 @@ impl FromStr for HexString { } } -#[derive(Clone, Copy, Debug)] -pub struct UtxoId(pub(crate) fuel_tx::UtxoId); - -#[Scalar(name = "UtxoId")] -impl ScalarType for UtxoId { - fn parse(value: Value) -> InputValueResult { - if let Value::String(value) = &value { - UtxoId::from_str(value.as_str()).map_err(Into::into) - } else { - Err(InputValueError::expected_type(value)) - } - } - - fn to_value(&self) -> Value { - Value::String(self.to_string()) - } -} - -impl FromStr for UtxoId { - type Err = String; - - fn from_str(s: &str) -> Result { - fuel_tx::UtxoId::from_str(s) - .map(Self) - .map_err(str::to_owned) - } -} - -impl Display for UtxoId { - fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { - let s = format!("{:#x}", self.0); - s.fmt(f) - } -} - -impl From for fuel_tx::UtxoId { - fn from(s: UtxoId) -> Self { - s.0 - } -} - -impl From for UtxoId { - fn from(utxo_id: fuel_tx::UtxoId) -> Self { - Self(utxo_id) - } -} - -impl CursorType for UtxoId { - type Error = String; - - fn decode_cursor(s: &str) -> Result { - Self::from_str(s) - } - - fn encode_cursor(&self) -> String { - self.to_string() - } -} - macro_rules! fuel_type_scalar { ($name:literal, $id:ident, $ft_id:ident, $len:expr) => { #[derive(Copy, Clone, Debug)] diff --git a/fuel-core/src/schema/scalars/tx_pointer.rs b/fuel-core/src/schema/scalars/tx_pointer.rs new file mode 100644 index 00000000000..75157d66622 --- /dev/null +++ b/fuel-core/src/schema/scalars/tx_pointer.rs @@ -0,0 +1,67 @@ +use async_graphql::{ + connection::CursorType, InputValueError, InputValueResult, Scalar, ScalarType, Value, +}; +use fuel_core_interfaces::common::fuel_tx; +use std::{ + fmt::{Display, Formatter}, + str::FromStr, +}; + +#[derive(Clone, Copy, Debug)] +pub struct TxPointer(pub(crate) fuel_tx::TxPointer); + +#[Scalar(name = "TxPointer")] +impl ScalarType for TxPointer { + fn parse(value: Value) -> InputValueResult { + if let Value::String(value) = &value { + TxPointer::from_str(value.as_str()).map_err(Into::into) + } else { + Err(InputValueError::expected_type(value)) + } + } + + fn to_value(&self) -> Value { + Value::String(self.to_string()) + } +} + +impl FromStr for TxPointer { + type Err = String; + + fn from_str(s: &str) -> Result { + fuel_tx::TxPointer::from_str(s) + .map(Self) + .map_err(str::to_owned) + } +} + +impl Display for TxPointer { + fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { + let s = format!("{:#x}", self.0); + s.fmt(f) + } +} + +impl From for fuel_tx::TxPointer { + fn from(s: TxPointer) -> Self { + s.0 + } +} + +impl From for TxPointer { + fn from(tx_pointer: fuel_tx::TxPointer) -> Self { + Self(tx_pointer) + } +} + +impl CursorType for TxPointer { + type Error = String; + + fn decode_cursor(s: &str) -> Result { + Self::from_str(s) + } + + fn encode_cursor(&self) -> String { + self.to_string() + } +} diff --git a/fuel-core/src/schema/scalars/utxo_id.rs b/fuel-core/src/schema/scalars/utxo_id.rs new file mode 100644 index 00000000000..47532a4eba4 --- /dev/null +++ b/fuel-core/src/schema/scalars/utxo_id.rs @@ -0,0 +1,67 @@ +use async_graphql::{ + connection::CursorType, InputValueError, InputValueResult, Scalar, ScalarType, Value, +}; +use fuel_core_interfaces::common::fuel_tx; +use std::{ + fmt::{Display, Formatter}, + str::FromStr, +}; + +#[derive(Clone, Copy, Debug)] +pub struct UtxoId(pub(crate) fuel_tx::UtxoId); + +#[Scalar(name = "UtxoId")] +impl ScalarType for UtxoId { + fn parse(value: Value) -> InputValueResult { + if let Value::String(value) = &value { + UtxoId::from_str(value.as_str()).map_err(Into::into) + } else { + Err(InputValueError::expected_type(value)) + } + } + + fn to_value(&self) -> Value { + Value::String(self.to_string()) + } +} + +impl FromStr for UtxoId { + type Err = String; + + fn from_str(s: &str) -> Result { + fuel_tx::UtxoId::from_str(s) + .map(Self) + .map_err(str::to_owned) + } +} + +impl Display for UtxoId { + fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { + let s = format!("{:#x}", self.0); + s.fmt(f) + } +} + +impl From for fuel_tx::UtxoId { + fn from(s: UtxoId) -> Self { + s.0 + } +} + +impl From for UtxoId { + fn from(utxo_id: fuel_tx::UtxoId) -> Self { + Self(utxo_id) + } +} + +impl CursorType for UtxoId { + type Error = String; + + fn decode_cursor(s: &str) -> Result { + Self::from_str(s) + } + + fn encode_cursor(&self) -> String { + self.to_string() + } +} diff --git a/fuel-core/src/schema/tx/input.rs b/fuel-core/src/schema/tx/input.rs index 0c36c760f90..f86c3d66754 100644 --- a/fuel-core/src/schema/tx/input.rs +++ b/fuel-core/src/schema/tx/input.rs @@ -1,3 +1,4 @@ +use crate::schema::scalars::TxPointer; use crate::schema::{ contract::Contract, scalars::{Address, AssetId, Bytes32, ContractId, HexString, MessageId, UtxoId, U64}, @@ -17,6 +18,7 @@ pub struct InputCoin { owner: Address, amount: U64, asset_id: AssetId, + tx_pointer: TxPointer, witness_index: u8, maturity: U64, predicate: HexString, @@ -41,6 +43,10 @@ impl InputCoin { self.asset_id } + async fn tx_pointer(&self) -> TxPointer { + self.tx_pointer + } + async fn witness_index(&self) -> u8 { self.witness_index } @@ -62,6 +68,7 @@ pub struct InputContract { utxo_id: UtxoId, balance_root: Bytes32, state_root: Bytes32, + tx_pointer: TxPointer, contract_id: ContractId, } @@ -79,6 +86,10 @@ impl InputContract { self.state_root } + async fn tx_pointer(&self) -> TxPointer { + self.tx_pointer + } + async fn contract(&self) -> Contract { self.contract_id.0.into() } @@ -148,6 +159,7 @@ impl From<&fuel_tx::Input> for Input { owner, amount, asset_id, + tx_pointer, witness_index, maturity, } => Input::Coin(InputCoin { @@ -155,6 +167,7 @@ impl From<&fuel_tx::Input> for Input { owner: Address(*owner), amount: (*amount).into(), asset_id: AssetId(*asset_id), + tx_pointer: TxPointer(*tx_pointer), witness_index: *witness_index, maturity: (*maturity).into(), predicate: HexString(Default::default()), @@ -165,6 +178,7 @@ impl From<&fuel_tx::Input> for Input { owner, amount, asset_id, + tx_pointer, maturity, predicate, predicate_data, @@ -173,6 +187,7 @@ impl From<&fuel_tx::Input> for Input { owner: Address(*owner), amount: (*amount).into(), asset_id: AssetId(*asset_id), + tx_pointer: TxPointer(*tx_pointer), witness_index: Default::default(), maturity: (*maturity).into(), predicate: HexString(predicate.clone()), @@ -182,11 +197,13 @@ impl From<&fuel_tx::Input> for Input { utxo_id, balance_root, state_root, + tx_pointer, contract_id, } => Input::Contract(InputContract { utxo_id: UtxoId(*utxo_id), balance_root: Bytes32(*balance_root), state_root: Bytes32(*state_root), + tx_pointer: TxPointer(*tx_pointer), contract_id: ContractId(*contract_id), }), fuel_tx::Input::MessageSigned { diff --git a/fuel-tests/Cargo.toml b/fuel-tests/Cargo.toml index eaa6ad05a07..8c98aee7e57 100644 --- a/fuel-tests/Cargo.toml +++ b/fuel-tests/Cargo.toml @@ -28,7 +28,7 @@ async-std = "1.12" chrono = { version = "0.4", features = ["serde"] } fuel-core = { path = "../fuel-core", features = ["test-helpers"], default-features = false } fuel-core-interfaces = { path = "../fuel-core-interfaces", features = ["test-helpers"] } -fuel-crypto = { version = "0.5", features = ["random"] } +fuel-crypto = { version = "0.6", features = ["random"] } fuel-gql-client = { path = "../fuel-client", features = ["test-helpers"] } fuel-txpool = { path = "../fuel-txpool" } futures = "0.3" diff --git a/fuel-tests/tests/balances.rs b/fuel-tests/tests/balances.rs index 4ad74d296a1..93f0fde556c 100644 --- a/fuel-tests/tests/balances.rs +++ b/fuel-tests/tests/balances.rs @@ -80,6 +80,7 @@ async fn balance() { asset_id: coin.asset_id.into(), maturity: coin.maturity.into(), witness_index: 0, + tx_pointer: Default::default(), }); } let tx = tx diff --git a/fuel-tests/tests/tx.rs b/fuel-tests/tests/tx.rs index c5d8d0d3de8..3f573326cad 100644 --- a/fuel-tests/tests/tx.rs +++ b/fuel-tests/tests/tx.rs @@ -464,6 +464,7 @@ impl TestContext { owner: from, amount, asset_id: Default::default(), + tx_pointer: Default::default(), witness_index: 0, maturity: 0, }], diff --git a/fuel-tests/tests/tx/predicates.rs b/fuel-tests/tests/tx/predicates.rs index ad168a2df22..9f16aa661d8 100644 --- a/fuel-tests/tests/tx/predicates.rs +++ b/fuel-tests/tests/tx/predicates.rs @@ -19,6 +19,7 @@ async fn transaction_with_predicates_is_rejected_when_feature_disabled() { rng.gen(), 500, asset_id, + Default::default(), 0, rng.gen::<[u8; 32]>().to_vec(), rng.gen::<[u8; 32]>().to_vec(), @@ -55,6 +56,7 @@ async fn transaction_with_predicate_is_executed_when_feature_enabled() { owner, amount, asset_id, + Default::default(), 0, predicate, vec![], @@ -103,6 +105,7 @@ async fn transaction_with_invalid_predicate_is_rejected_when_feature_is_enabled( owner, amount, asset_id, + Default::default(), 0, predicate, vec![], diff --git a/fuel-tests/tests/tx/utxo_validation.rs b/fuel-tests/tests/tx/utxo_validation.rs index 0507d3eb11e..05d66163095 100644 --- a/fuel-tests/tests/tx/utxo_validation.rs +++ b/fuel-tests/tests/tx/utxo_validation.rs @@ -32,12 +32,14 @@ async fn submit_utxo_verified_tx_with_min_gas_price() { rng.gen(), 1000 + i, Default::default(), + Default::default(), 0, ) .add_input(Input::Contract { utxo_id: Default::default(), balance_root: Default::default(), state_root: Default::default(), + tx_pointer: Default::default(), contract_id, }) .add_output(Output::Change { @@ -134,6 +136,7 @@ async fn dry_run_override_utxo_validation() { rng.gen(), 1000, AssetId::default(), + Default::default(), 0, Default::default(), )) @@ -142,6 +145,7 @@ async fn dry_run_override_utxo_validation() { rng.gen(), rng.gen(), asset_id, + Default::default(), 0, Default::default(), )) @@ -177,6 +181,7 @@ async fn dry_run_no_utxo_validation_override() { rng.gen(), 1000, AssetId::default(), + Default::default(), 0, Default::default(), )) @@ -185,6 +190,7 @@ async fn dry_run_no_utxo_validation_override() { rng.gen(), rng.gen(), asset_id, + Default::default(), 0, Default::default(), )) @@ -221,6 +227,7 @@ async fn concurrent_tx_submission_produces_expected_blocks() { rng.gen(), rng.gen_range(1..1000), Default::default(), + Default::default(), 0, ) .add_output(Output::change(rng.gen(), 0, Default::default())) diff --git a/fuel-txpool/src/containers/dependency.rs b/fuel-txpool/src/containers/dependency.rs index ae409443ae0..5f6579386f1 100644 --- a/fuel-txpool/src/containers/dependency.rs +++ b/fuel-txpool/src/containers/dependency.rs @@ -668,6 +668,7 @@ mod tests { owner: Address::default(), amount: 10, asset_id: AssetId::default(), + tx_pointer: Default::default(), witness_index: 0, maturity: 0, }; From 7c2a64508d47d53f4f03a2199875287e25131462 Mon Sep 17 00:00:00 2001 From: Brandon Vrooman Date: Tue, 9 Aug 2022 19:31:53 -0400 Subject: [PATCH 2/6] fix unused variable warning --- fuel-core/src/database.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fuel-core/src/database.rs b/fuel-core/src/database.rs index 567a15c6fb3..1e6e197278e 100644 --- a/fuel-core/src/database.rs +++ b/fuel-core/src/database.rs @@ -262,7 +262,7 @@ impl InterpreterStorage for Database { Ok(height.into()) } - fn timestamp(&self, height: u32) -> Result { + fn timestamp(&self, _height: u32) -> Result { todo!() } From c9b4b939d22287e995d00fff3503fc15508da78d Mon Sep 17 00:00:00 2001 From: Brandon Vrooman Date: Tue, 9 Aug 2022 19:44:58 -0400 Subject: [PATCH 3/6] Update fuel_gql_client__client__schema__tx__tests__transparent_transaction_by_id_query_gql_output.snap --- ..._tests__transparent_transaction_by_id_query_gql_output.snap | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/fuel-client/src/client/schema/snapshots/fuel_gql_client__client__schema__tx__tests__transparent_transaction_by_id_query_gql_output.snap b/fuel-client/src/client/schema/snapshots/fuel_gql_client__client__schema__tx__tests__transparent_transaction_by_id_query_gql_output.snap index 32faa9fee9b..151a58baeb9 100644 --- a/fuel-client/src/client/schema/snapshots/fuel_gql_client__client__schema__tx__tests__transparent_transaction_by_id_query_gql_output.snap +++ b/fuel-client/src/client/schema/snapshots/fuel_gql_client__client__schema__tx__tests__transparent_transaction_by_id_query_gql_output.snap @@ -1,6 +1,5 @@ --- source: fuel-client/src/client/schema/tx.rs -assertion_line: 275 expression: operation.query --- query Query($_0: TransactionId!) { @@ -19,6 +18,7 @@ query Query($_0: TransactionId!) { owner amount assetId + txPointer witnessIndex maturity predicate @@ -28,6 +28,7 @@ query Query($_0: TransactionId!) { utxoId balanceRoot stateRoot + txPointer contract { id } From ecaf1a56cd736da853fe180cc44c0ba229bd642b Mon Sep 17 00:00:00 2001 From: Brandon Kite Date: Tue, 9 Aug 2022 18:06:06 -0700 Subject: [PATCH 4/6] stub out tests for current block height --- fuel-core/src/executor.rs | 132 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 132 insertions(+) diff --git a/fuel-core/src/executor.rs b/fuel-core/src/executor.rs index a37b24182ee..febb5dcd397 100644 --- a/fuel-core/src/executor.rs +++ b/fuel-core/src/executor.rs @@ -1875,4 +1875,136 @@ mod tests { )) )); } + + #[tokio::test] + async fn get_block_height_returns_current_executing_block() { + let mut rng = StdRng::seed_from_u64(1234); + + // return current block height + let script = vec![Opcode::BHEI(0x10), Opcode::RET(0x10)]; + let tx = TransactionBuilder::script(script.into_iter().collect(), vec![]) + .gas_limit(10000) + .add_unsigned_coin_input( + rng.gen(), + rng.gen(), + 1000, + AssetId::zeroed(), + Default::default(), + 0, + ) + .finalize(); + + // setup block + let block_height = rng.gen_range(5u32..1000u32); + + let mut block = FuelBlock { + header: FuelBlockHeader { + height: block_height.into(), + ..Default::default() + }, + transactions: vec![tx.clone()], + }; + + // setup db with coin to spend + let mut database = Database::default(); + let coin_input = &tx.inputs()[0]; + Storage::::insert( + &mut database, + coin_input.utxo_id().unwrap(), + &Coin { + owner: *coin_input.input_owner().unwrap(), + amount: coin_input.amount().unwrap(), + asset_id: *coin_input.asset_id().unwrap(), + maturity: (coin_input.maturity().unwrap()).into(), + block_created: 0u64.into(), + status: CoinStatus::Unspent, + }, + ) + .unwrap(); + + // make executor with db + let executor = Executor { + database: database.clone(), + config: Config { + utxo_validation: true, + ..Config::local_node() + }, + }; + + executor + .execute(&mut block, ExecutionMode::Production) + .await + .unwrap(); + + let receipts = Storage::>::get(&database, &tx.id()) + .unwrap() + .unwrap(); + assert_eq!(block_height as u64, receipts[0].val().unwrap()); + } + + #[tokio::test] + async fn get_time_returns_current_executing_block_time() { + let mut rng = StdRng::seed_from_u64(1234); + + // return current block height + let script = vec![Opcode::BHEI(0x10), Opcode::RET(0x10)]; + let tx = TransactionBuilder::script(script.into_iter().collect(), vec![]) + .gas_limit(10000) + .add_unsigned_coin_input( + rng.gen(), + rng.gen(), + 1000, + AssetId::zeroed(), + Default::default(), + 0, + ) + .finalize(); + + // setup block + let block_height = rng.gen_range(5u32..1000u32); + + let mut block = FuelBlock { + header: FuelBlockHeader { + height: block_height.into(), + ..Default::default() + }, + transactions: vec![tx.clone()], + }; + + // setup db with coin to spend + let mut database = Database::default(); + let coin_input = &tx.inputs()[0]; + Storage::::insert( + &mut database, + coin_input.utxo_id().unwrap(), + &Coin { + owner: *coin_input.input_owner().unwrap(), + amount: coin_input.amount().unwrap(), + asset_id: *coin_input.asset_id().unwrap(), + maturity: (coin_input.maturity().unwrap()).into(), + block_created: 0u64.into(), + status: CoinStatus::Unspent, + }, + ) + .unwrap(); + + // make executor with db + let executor = Executor { + database: database.clone(), + config: Config { + utxo_validation: true, + ..Config::local_node() + }, + }; + + executor + .execute(&mut block, ExecutionMode::Production) + .await + .unwrap(); + + let receipts = Storage::>::get(&database, &tx.id()) + .unwrap() + .unwrap(); + assert_eq!(block_height as u64, receipts[0].val().unwrap()); + } } From f0725e4f96006984eaa2864f3250f1e45ba4533e Mon Sep 17 00:00:00 2001 From: Brandon Kite Date: Tue, 9 Aug 2022 18:49:04 -0700 Subject: [PATCH 5/6] finish tests and impl current block header logic in executor --- fuel-core/src/database.rs | 11 +++++++++-- fuel-core/src/executor.rs | 25 +++++++++++++++++++++++-- 2 files changed, 32 insertions(+), 4 deletions(-) diff --git a/fuel-core/src/database.rs b/fuel-core/src/database.rs index 1e6e197278e..63ba38f1352 100644 --- a/fuel-core/src/database.rs +++ b/fuel-core/src/database.rs @@ -262,8 +262,15 @@ impl InterpreterStorage for Database { Ok(height.into()) } - fn timestamp(&self, _height: u32) -> Result { - todo!() + fn timestamp(&self, height: u32) -> Result { + let id = self.block_hash(height.into())?; + let block = Storage::::get(self, &id)?.unwrap_or_default(); + block + .headers + .time + .timestamp() + .try_into() + .map_err(|e| Self::DataError::DatabaseError(Box::new(e))) } fn block_hash(&self, block_height: u32) -> Result { diff --git a/fuel-core/src/executor.rs b/fuel-core/src/executor.rs index febb5dcd397..e9fdfdd2884 100644 --- a/fuel-core/src/executor.rs +++ b/fuel-core/src/executor.rs @@ -89,6 +89,13 @@ impl Executor { }; let mut block_db_transaction = self.database.transaction(); + // Insert the current headers (including time, block height, producer into the db tx) + Storage::::insert( + block_db_transaction.deref_mut(), + &Bytes32::zeroed(), // use id of zero as current block + &block.to_db_block(), + )?; + let mut txs_merkle = MerkleTree::new(); let mut tx_status = vec![]; let mut coinbase = 0u64; @@ -285,6 +292,12 @@ impl Executor { block_db_transaction.deref_mut(), )?; + // cleanup unfinalized headers (block height + time + producer) + Storage::::remove( + block_db_transaction.deref_mut(), + &Bytes32::zeroed(), + )?; + // insert block into database Storage::::insert( block_db_transaction.deref_mut(), @@ -817,6 +830,7 @@ impl From for Error { mod tests { use super::*; use crate::model::FuelBlockHeader; + use chrono::TimeZone; use fuel_core_interfaces::model::{CheckedMessage, Message}; use fuel_core_interfaces::{ common::{ @@ -1947,7 +1961,11 @@ mod tests { let mut rng = StdRng::seed_from_u64(1234); // return current block height - let script = vec![Opcode::BHEI(0x10), Opcode::RET(0x10)]; + let script = vec![ + Opcode::BHEI(0x10), + Opcode::TIME(0x11, 0x10), + Opcode::RET(0x11), + ]; let tx = TransactionBuilder::script(script.into_iter().collect(), vec![]) .gas_limit(10000) .add_unsigned_coin_input( @@ -1962,10 +1980,12 @@ mod tests { // setup block let block_height = rng.gen_range(5u32..1000u32); + let time = rng.gen_range(1u32..u32::MAX); let mut block = FuelBlock { header: FuelBlockHeader { height: block_height.into(), + time: Utc.timestamp(time as i64, 0), ..Default::default() }, transactions: vec![tx.clone()], @@ -2005,6 +2025,7 @@ mod tests { let receipts = Storage::>::get(&database, &tx.id()) .unwrap() .unwrap(); - assert_eq!(block_height as u64, receipts[0].val().unwrap()); + + assert_eq!(time as u64, receipts[0].val().unwrap()); } } From 9b990c5e361f82dd4d8c3112c6620e4d4d687ecc Mon Sep 17 00:00:00 2001 From: Brandon Kite Date: Tue, 9 Aug 2022 20:05:38 -0700 Subject: [PATCH 6/6] appease clippy --- fuel-core/src/database.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fuel-core/src/database.rs b/fuel-core/src/database.rs index 63ba38f1352..3c22f6bf732 100644 --- a/fuel-core/src/database.rs +++ b/fuel-core/src/database.rs @@ -263,7 +263,7 @@ impl InterpreterStorage for Database { } fn timestamp(&self, height: u32) -> Result { - let id = self.block_hash(height.into())?; + let id = self.block_hash(height)?; let block = Storage::::get(self, &id)?.unwrap_or_default(); block .headers