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

Complete feature std-fs-io in casper-types for wasm compilation #4714

Open
wants to merge 140 commits into
base: feat-2.0
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 88 commits
Commits
Show all changes
140 commits
Select commit Hold shift + click to select a range
5560476
sdk feature
gRoussac Jul 26, 2023
6f22749
Timestamp::now not available in wasm
gRoussac Aug 3, 2023
e2ca29d
// bad commit
gRoussac Aug 3, 2023
d7fff7b
Merge branch 'feat-2.0' into rustSDK
gRoussac Aug 15, 2023
e8bce3c
Add flag
gRoussac Aug 15, 2023
7af4580
Merge branch 'feat-2.0' of github.com:casper-network/casper-node into…
gRoussac Sep 8, 2023
cf13bd2
remove cfg
gRoussac Sep 14, 2023
ea3f454
Merge branch 'rustSDK' of github.com:casper-network/casper-node into …
gRoussac Sep 14, 2023
5a29c9e
revert
gRoussac Sep 14, 2023
7c501bd
Merge branch 'feat-2.0' of github.com:casper-network/casper-node into…
gRoussac Sep 14, 2023
6f5bd22
Sorry ide complaining on toml files
gRoussac Sep 14, 2023
0c407c5
cargo fmt
gRoussac Sep 14, 2023
32a654d
Try to fix lint
gRoussac Sep 14, 2023
5a6e7b6
Try to pass CI/CD with cargo check and lint
gRoussac Sep 15, 2023
b3e382e
build check lint
gRoussac Sep 15, 2023
1b7bb11
unused imports
gRoussac Sep 16, 2023
06ac481
Update changelog for types and not node
gRoussac Sep 23, 2023
c61ce65
Bad makefile
gRoussac Sep 23, 2023
a932487
Revert change on std
gRoussac Sep 28, 2023
76c3e45
getrandom/js missing
gRoussac Oct 4, 2023
88587b1
Merge branch 'feat-2.0' of github.com:casper-network/casper-node into…
gRoussac Oct 4, 2023
aec2554
Merge branch 'feat-2.0' of github.com:casper-network/casper-node into…
gRoussac May 13, 2024
78e5a7a
Merge PR std-fs-io
gRoussac May 13, 2024
e8cf36c
Bad import unusued
gRoussac May 13, 2024
0ab9466
again gating feat
gRoussac May 13, 2024
c88839b
Pub transaction
gRoussac May 13, 2024
9866692
docs required
gRoussac May 13, 2024
dda28b9
Docs
gRoussac May 13, 2024
b6b4a46
Warnings on Cargo check
gRoussac May 13, 2024
59a1e93
cargo lock update
gRoussac May 13, 2024
299164a
Bad merge
gRoussac May 13, 2024
e606349
test
gRoussac May 13, 2024
4c04d90
test
gRoussac May 13, 2024
7f8c676
test
gRoussac May 13, 2024
ec9915e
revert
gRoussac May 13, 2024
92c7a33
Revert formating changes
gRoussac May 13, 2024
5073ebe
revert
gRoussac May 13, 2024
5c7da3a
Revert
gRoussac May 13, 2024
fc88cf3
Merge branch 'feat-2.0' of github.com:casper-network/casper-node into…
gRoussac May 20, 2024
f863468
pub
gRoussac May 26, 2024
f788fc3
Doc
gRoussac May 26, 2024
58d5df7
Merge branch 'feat-2.0' of github.com:casper-network/casper-node into…
gRoussac May 27, 2024
d02749f
pub on TransactionV1Builder
gRoussac May 30, 2024
a4c0b35
Add documentation
gRoussac May 30, 2024
3818bff
Merge branch 'feat-2.0' of github.com:casper-network/casper-node into…
gRoussac May 31, 2024
16462ae
pub
gRoussac Jun 1, 2024
d8e7631
Doc
gRoussac Jun 3, 2024
502398d
debug
gRoussac Jun 3, 2024
cbc30db
test timestamp
gRoussac Jun 4, 2024
04d80de
Merge branch 'feat-2.0' of github.com:casper-network/casper-node into…
gRoussac Jun 6, 2024
812abf7
Remove example in doc
gRoussac Jun 6, 2024
e3bc04f
clippy
gRoussac Jun 6, 2024
54fd6d1
fmt
gRoussac Jun 6, 2024
e424c8c
Merge branch 'feat-2.0' of github.com:casper-network/casper-node into…
gRoussac Jun 7, 2024
52dfe16
cargo audit update -p h2 --precise 0.3.26
gRoussac Jun 7, 2024
af2b5ab
revert
gRoussac Jun 7, 2024
24fcb98
Merge branch 'feat-2.0' of github.com:casper-network/casper-node into…
gRoussac Jun 10, 2024
df42898
Update PR
gRoussac Jun 10, 2024
adaa6fd
gate out libc
gRoussac Jun 10, 2024
492b7e4
cargo update -p h2 --precise 0.3.26
gRoussac Jun 10, 2024
9e9928e
test
gRoussac Jun 10, 2024
a5a4b55
Revert
gRoussac Jun 10, 2024
337884f
Itertools not std
gRoussac Jun 10, 2024
78debf8
Itertools
gRoussac Jun 10, 2024
fadabc7
Revert
gRoussac Jun 10, 2024
68e3616
Remove default feat for itertools
gRoussac Jun 10, 2024
5e78421
test
gRoussac Jun 10, 2024
8ba8e97
Wording
gRoussac Jun 10, 2024
9d50c27
body on TransactionV1Builder
gRoussac Jun 10, 2024
7206acc
Typo
gRoussac Jun 10, 2024
43f4e90
Change changelog
gRoussac Jun 10, 2024
397a236
Merge branch 'feat-2.0' of github.com:casper-network/casper-node into…
gRoussac Jun 10, 2024
eb1e76d
Add cargo checking --lib on types and fix some warnings
gRoussac Jun 11, 2024
a921f70
Add cargo check on std-fs-io feature
gRoussac Jun 11, 2024
b8f2402
add to_hex_string to TransactionHash and DeployHash
gRoussac Jun 11, 2024
335c158
Revert "Add cargo checking --lib on types and fix some warnings"
gRoussac Jun 11, 2024
013ec8c
to_hex_string in block hash
gRoussac Jun 12, 2024
f4b758e
Missing import
gRoussac Jun 12, 2024
36af5f8
Bad commit
gRoussac Jun 12, 2024
d533f9a
Remove warning
gRoussac Jun 13, 2024
d1725f8
Bad commit
gRoussac Jun 13, 2024
b4ae5f7
Add to_hex_string to some hashes
gRoussac Jun 16, 2024
44b95de
Merge branch 'feat-2.0' of github.com:casper-network/casper-node into…
gRoussac Jun 18, 2024
9387fe2
Merge branch 'feat-2.0' of github.com:casper-network/casper-node into…
gRoussac Jun 18, 2024
42cc1c9
Merge branch 'feat-2.0' of github.com:casper-network/casper-node into…
gRoussac Jun 24, 2024
0bb3049
Merge branch 'feat-2.0' of github.com:casper-network/casper-node into…
gRoussac Jun 27, 2024
5a9b891
Merge branch 'feat-2.0' of github.com:casper-network/casper-node into…
gRoussac Jul 2, 2024
3c772c7
Merge branch 'feat-2.0' of github.com:casper-network/casper-node into…
gRoussac Jul 9, 2024
e731ef6
Revert cargo lock commit
gRoussac Jul 10, 2024
e41f66d
Bad export
gRoussac Jul 12, 2024
71f1341
Revert
gRoussac Jul 12, 2024
6bf2f6d
Bad commit
gRoussac Jul 12, 2024
745b85c
Again sorry
gRoussac Jul 12, 2024
7161576
Merge branch 'feat-2.0' of github.com:casper-network/casper-node into…
gRoussac Jul 18, 2024
4827596
Merge branch 'feat-2.0' of github.com:casper-network/casper-node into…
gRoussac Aug 5, 2024
faf1f2d
Update cargo lock
gRoussac Aug 5, 2024
a3485bf
Merge branch 'feat-2.0' of github.com:casper-network/casper-node into…
gRoussac Aug 15, 2024
598173a
Merge branch 'feat-2.0' of github.com:casper-network/casper-node into…
gRoussac Aug 19, 2024
06e962b
Merge branch 'feat-2.0' of github.com:casper-network/casper-node into…
gRoussac Aug 26, 2024
64317b6
Merge branch 'feat-2.0' of github.com:casper-network/casper-node into…
gRoussac Sep 4, 2024
60d6ec0
Fix cargo audit
gRoussac Sep 4, 2024
db7d22b
Test cargo audit
gRoussac Sep 4, 2024
d62c524
clippy
gRoussac Sep 4, 2024
087bff7
Test cargo audit
gRoussac Sep 4, 2024
a10c140
test cid/cd
gRoussac Sep 4, 2024
db10abd
Revert
gRoussac Sep 4, 2024
2516642
Merge branch 'feat-2.0' of github.com:casper-network/casper-node into…
gRoussac Sep 11, 2024
45bd9e5
Doc + lint
gRoussac Sep 11, 2024
e009a45
Changing TransactionV1 structure. From now on a TransactionV1 consist…
Sep 26, 2024
156f834
Applying fmt fixes
Sep 27, 2024
43b8bcf
Fixing unit tests
Oct 1, 2024
3567921
Merging feat-2.0
Oct 4, 2024
2cac516
Merge branch 'feat-2.0' of github.com:casper-network/casper-node into…
gRoussac Oct 5, 2024
b3ce0be
Merge remote-tracking branch 'jakub/restructuring_transaction_datatyp…
gRoussac Oct 7, 2024
47bb9af
Added missing tests to TransactionAcceptor
Oct 7, 2024
149c569
stash
gRoussac Oct 8, 2024
7c4705d
Merge branch 'restructuring_transaction_datatype' of github.com:zajko…
gRoussac Oct 8, 2024
f7c3951
Fixed broken import
Oct 8, 2024
1afd8ae
Merge branch 'restructuring_transaction_datatype' of github.com:zajko…
gRoussac Oct 8, 2024
9309207
Added check for "fields" field ordering for deserialization of Transa…
Oct 9, 2024
158ea9e
Fmt fixes
Oct 9, 2024
458d4d0
Lint fixes
Oct 9, 2024
f3ffe86
trying to debug charge_when_session_code_succeeds test
Oct 9, 2024
5f496e9
Merge branch 'restructuring_transaction_datatype' of github.com:zajko…
gRoussac Oct 9, 2024
68347b0
Fixing charge_when_session_code_succeeds test
Oct 9, 2024
2a016fe
Merge branch 'restructuring_transaction_datatype' of github.com:zajko…
gRoussac Oct 10, 2024
1f2f1b0
Merge branch 'restructuring_transaction_datatype' of github.com:zajko…
gRoussac Oct 10, 2024
51890a5
Merge branch 'restructuring_transaction_datatype' of github.com:zajko…
gRoussac Oct 15, 2024
a1e0350
Merge branch 'feat-2.0' of github.com:casper-network/casper-node into…
gRoussac Oct 15, 2024
8aa94ec
Expose some methods to get chain name / target / entry point
gRoussac Oct 17, 2024
82da161
Manage unwraps
gRoussac Oct 17, 2024
4bbd6e3
remove comment
gRoussac Oct 17, 2024
91713a0
revert entry_point()
gRoussac Oct 17, 2024
f8c6c2d
Revert, expose chain_name + is_standard_payment
gRoussac Oct 17, 2024
e779e86
Merge branch 'restructuring_transaction_datatype' of github.com:zajko…
gRoussac Oct 17, 2024
022481f
Merge branch 'rustSDK-feat-2.0-transaction' into rustSDK-feat-2.0
gRoussac Oct 17, 2024
1a899e2
Merge branch 'feat-2.0' of github.com:casper-network/casper-node into…
gRoussac Oct 17, 2024
a41abcf
Missing import
gRoussac Oct 17, 2024
63977d6
again bad import
gRoussac Oct 17, 2024
c4f38a8
test TransactionV1Builder new
gRoussac Oct 18, 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
154 changes: 67 additions & 87 deletions Cargo.lock

Large diffs are not rendered by default.

12 changes: 10 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,10 @@ check-std-features:
cd smart_contracts/contract && $(CARGO) check --all-targets --no-default-features --features=std
cd smart_contracts/contract && $(CARGO) check --all-targets --features=std

.PHONY: check-testing-features
check-std-fs-io-features:
cd types && $(CARGO) check --all-targets --features=std-fs-io
cd types && $(CARGO) check --lib --features=std-fs-io

check-testing-features:
cd types && $(CARGO) check --all-targets --no-default-features --features=testing
cd types && $(CARGO) check --all-targets --features=testing
Expand All @@ -129,12 +132,16 @@ lint-contracts-rs:
cd smart_contracts/contracts && $(CARGO) clippy $(patsubst %, -p %, $(ALL_CONTRACTS)) -- -D warnings -A renamed_and_removed_lints

.PHONY: lint
lint: lint-contracts-rs lint-default-features lint-all-features lint-smart-contracts
lint: lint-contracts-rs lint-default-features lint-all-features lint-smart-contracts lint-no-default-features

.PHONY: lint-default-features
lint-default-features:
$(CARGO) clippy --all-targets -- -D warnings

.PHONY: lint-no-default-features
lint-no-default-features:
$(CARGO) clippy --all-targets --no-default-features -- -D warnings

.PHONY: lint-all-features
lint-all-features:
$(CARGO) clippy --all-targets --all-features -- -D warnings
Expand Down Expand Up @@ -168,6 +175,7 @@ check-rs: \
audit \
check-no-default-features \
check-std-features \
check-std-fs-io-features \
check-testing-features \
test-rs \
test-rs-no-default-features \
Expand Down
2 changes: 1 addition & 1 deletion node/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -546,4 +546,4 @@ All notable changes to this project will be documented in this file. The format
[1.1.1]: https://github.com/casper-network/casper-node/compare/v1.0.1...v1.1.1
[1.1.0]: https://github.com/casper-network/casper-node/compare/v1.0.1...v1.1.1
[1.0.1]: https://github.com/casper-network/casper-node/compare/v1.0.0...v1.0.1
[1.0.0]: https://github.com/casper-network/casper-node/releases/tag/v1.0.0
[1.0.0]: https://github.com/casper-network/casper-node/releases/tag/v1.0.0
4 changes: 2 additions & 2 deletions types/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ All notable changes to this project will be documented in this file. The format
### Added
* Add new `EntryPointType::Install`, `EntryPointType::Normal`, `EntryPointAccess::Abstract` variants to support implementation of a factory pattern.
* Add new types (`types/src/binary_port`) to support the BinaryPort interface
* Remove filesystem I/O functionality from the `std` feature, and gated this behind a new feature `std-fs-io` which depends upon `std`.



## [Unreleased] (node 1.5.4)
## [Unreleased] (node 1.6)

### Changed
* Remove filesystem I/O functionality from the `std` feature, and gated this behind a new feature `std-fs-io` which depends upon `std`.
Expand Down
4 changes: 2 additions & 2 deletions types/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ itertools = { version = "0.10.3", default-features = false }
libc = { version = "0.2.146", optional = true, default-features = false }
k256 = { version = "0.13.1", default-features = false, features = ["ecdsa", "sha256"] }
num = { version = "0.4.0", default-features = false, features = ["alloc"] }
num-derive = { version = "0.3.0", default-features = false }
num-derive = { version = "0.4.0", default-features = false }
num-integer = { version = "0.1.42", default-features = false }
num-rational = { version = "0.4.0", default-features = false, features = ["serde"] }
num-traits = { version = "0.2.10", default-features = false }
Expand All @@ -43,7 +43,7 @@ serde = { version = "1", default-features = false, features = ["alloc", "derive"
serde_bytes = { version = "0.11.5", default-features = false, features = ["alloc"] }
serde_json = { version = "1.0.59", default-features = false, features = ["alloc"] }
strum = { version = "0.24", features = ["derive"], optional = true }
thiserror = {version = "1", optional = true }
thiserror = { version = "1", optional = true }
tracing = { version = "0.1.37", default-features = false }
uint = { version = "0.9.0", default-features = false }
untrusted = { version = "0.7.1", optional = true }
Expand Down
5 changes: 5 additions & 0 deletions types/src/account/account_hash.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,11 @@ impl AccountHash {
)
}

/// Hexadecimal representation of the hash.
pub fn to_hex_string(&self) -> String {
base16::encode_lower(&self.0)
}

/// Parses a string formatted as per `Self::to_formatted_string()` into an `AccountHash`.
pub fn from_formatted_str(input: &str) -> Result<Self, FromStrError> {
let remainder = input
Expand Down
3 changes: 0 additions & 3 deletions types/src/account/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,3 @@ impl Display for FromStrError {
}
}
}
/// Associated error type of `TryFrom<&[u8]>` for [`AccountHash`](super::AccountHash).
#[derive(Debug)]
pub struct TryFromSliceForAccountHashError(());
30 changes: 23 additions & 7 deletions types/src/addressable_entity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,13 +79,24 @@ pub const MAX_GROUPS: u8 = 10;
/// Maximum number of URefs which can be assigned across all user groups.
pub const MAX_TOTAL_UREFS: usize = 100;

const ADDRESSABLE_ENTITY_STRING_PREFIX: &str = "addressable-entity-";

const ENTITY_PREFIX: &str = "entity-";
const ACCOUNT_ENTITY_PREFIX: &str = "account-";
const CONTRACT_ENTITY_PREFIX: &str = "contract-";
const SYSTEM_ENTITY_PREFIX: &str = "system-";
const NAMED_KEY_PREFIX: &str = "named-key-";
/// The prefix applied to the hex-encoded `Addressable Entity` to produce a formatted string
/// representation.
pub const ADDRESSABLE_ENTITY_STRING_PREFIX: &str = "addressable-entity-";
/// The prefix applied to the hex-encoded `Entity` to produce a formatted string
/// representation.
pub const ENTITY_PREFIX: &str = "entity-";
/// The prefix applied to the hex-encoded `Account` to produce a formatted string
/// representation.
pub const ACCOUNT_ENTITY_PREFIX: &str = "account-";
/// The prefix applied to the hex-encoded `Smart contract` to produce a formatted string
/// representation.
pub const CONTRACT_ENTITY_PREFIX: &str = "contract-";
/// The prefix applied to the hex-encoded `System entity account or contract` to produce a formatted
/// string representation.
pub const SYSTEM_ENTITY_PREFIX: &str = "system-";
/// The prefix applied to the hex-encoded `Named Key` to produce a formatted string
/// representation.
pub const NAMED_KEY_PREFIX: &str = "named-key-";

/// Set of errors which may happen when working with contract headers.
#[derive(Debug, PartialEq, Eq)]
Expand Down Expand Up @@ -279,6 +290,11 @@ impl AddressableEntityHash {
)
}

/// Hexadecimal representation of the hash.
pub fn to_hex_string(&self) -> String {
base16::encode_lower(&self.0)
}

/// Parses a string formatted as per `Self::to_formatted_string()` into a
/// `AddressableEntityHash`.
pub fn from_formatted_str(input: &str) -> Result<Self, FromStrError> {
Expand Down
7 changes: 6 additions & 1 deletion types/src/block/block_hash.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use alloc::vec::Vec;
use alloc::{string::String, vec::Vec};
use core::fmt::{self, Display, Formatter};

#[cfg(feature = "datasize")]
Expand Down Expand Up @@ -53,6 +53,11 @@ impl BlockHash {
&self.0
}

/// Hexadecimal representation of the hash.
pub fn to_hex_string(&self) -> String {
base16::encode_lower(self.inner())
}

// This method is not intended to be used by third party crates.
#[doc(hidden)]
#[cfg(feature = "json-schema")]
Expand Down
5 changes: 3 additions & 2 deletions types/src/chainspec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,12 @@ pub use activation_point::ActivationPoint;
pub use chainspec_raw_bytes::ChainspecRawBytes;
#[cfg(any(feature = "testing", test))]
pub use core_config::DEFAULT_FEE_HANDLING;
#[cfg(any(feature = "testing", test))]
pub use core_config::DEFAULT_GAS_HOLD_BALANCE_HANDLING;
#[cfg(any(feature = "std", test))]
pub use core_config::DEFAULT_REFUND_HANDLING;
pub use core_config::{
ConsensusProtocolName, CoreConfig, LegacyRequiredFinality, DEFAULT_GAS_HOLD_BALANCE_HANDLING,
DEFAULT_GAS_HOLD_INTERVAL,
ConsensusProtocolName, CoreConfig, LegacyRequiredFinality, DEFAULT_GAS_HOLD_INTERVAL,
};
pub use fee_handling::FeeHandling;
#[cfg(any(feature = "testing", test))]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,12 @@ use datasize::DataSize;
use rand::Rng;
use serde::{Deserialize, Serialize};

#[cfg(any(feature = "testing", test))]
use crate::testing::TestRng;
use crate::{
bytesrepr::{self, FromBytes, ToBytes},
transaction::TransactionCategory,
INSTALL_UPGRADE_LANE_ID,
};
#[cfg(any(feature = "testing", test))]
use crate::{testing::TestRng, INSTALL_UPGRADE_LANE_ID};

/// Default gas limit of install / upgrade contracts
pub const DEFAULT_INSTALL_UPGRADE_GAS_LIMIT: u64 = 3_500_000_000_000;
Expand Down
13 changes: 9 additions & 4 deletions types/src/chainspec/vm_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,20 @@ mod storage_costs;
mod system_config;
mod wasm_config;

pub use auction_costs::{AuctionCosts, DEFAULT_ADD_BID_COST, DEFAULT_DELEGATE_COST};
pub use auction_costs::AuctionCosts;
#[cfg(any(feature = "testing", test))]
pub use auction_costs::{DEFAULT_ADD_BID_COST, DEFAULT_DELEGATE_COST};
pub use chainspec_registry::ChainspecRegistry;
pub use handle_payment_costs::HandlePaymentCosts;
#[cfg(any(feature = "testing", test))]
pub use host_function_costs::DEFAULT_NEW_DICTIONARY_COST;
pub use host_function_costs::{
Cost as HostFunctionCost, HostFunction, HostFunctionCosts,
DEFAULT_HOST_FUNCTION_NEW_DICTIONARY, DEFAULT_NEW_DICTIONARY_COST,
Cost as HostFunctionCost, HostFunction, HostFunctionCosts, DEFAULT_HOST_FUNCTION_NEW_DICTIONARY,
};
pub use message_limits::MessageLimits;
pub use mint_costs::{MintCosts, DEFAULT_TRANSFER_COST};
pub use mint_costs::MintCosts;
#[cfg(any(feature = "testing", test))]
pub use mint_costs::DEFAULT_TRANSFER_COST;
pub use opcode_costs::{BrTableCost, ControlFlowCosts, OpcodeCosts};
#[cfg(any(feature = "testing", test))]
pub use opcode_costs::{
Expand Down
1 change: 1 addition & 0 deletions types/src/cl_value.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//! CLvalue type
use alloc::{string::String, vec::Vec};
use core::fmt::{self, Display, Formatter};

Expand Down
10 changes: 10 additions & 0 deletions types/src/crypto/asymmetric_key.rs
Original file line number Diff line number Diff line change
Expand Up @@ -503,6 +503,11 @@ impl PublicKey {
AccountHash::from(self)
}

/// Hexadecimal representation of the key.
pub fn to_hex_string(&self) -> String {
self.to_hex()
}

/// Returns `true` if this public key is of the `System` variant.
pub fn is_system(&self) -> bool {
matches!(self, PublicKey::System)
Expand Down Expand Up @@ -967,6 +972,11 @@ impl Signature {
Signature::Secp256k1(_) => SECP256K1,
}
}

/// Hexadecimal representation of the signature.
pub fn to_hex_string(&self) -> String {
self.to_hex()
}
}

impl AsymmetricType<'_> for Signature {
Expand Down
9 changes: 9 additions & 0 deletions types/src/crypto/asymmetric_key/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ fn known_secret_key_to_pem(expected_key: &SecretKey, known_key_pem: &str, expect
assert_eq!(expected_tag, decoded.tag());
}

#[cfg(any(feature = "std-fs-io", test))]
fn secret_key_file_roundtrip(secret_key: SecretKey) {
let tempdir = tempfile::tempdir().unwrap();
let path = tempdir.path().join("test_secret_key.pem");
Expand Down Expand Up @@ -140,6 +141,7 @@ fn known_public_key_to_pem(known_key_hex: &str, known_key_pem: &str) {
assert_eq!(key_bytes, Into::<Vec<u8>>::into(decoded));
}

#[cfg(any(feature = "std-fs-io", test))]
fn public_key_file_roundtrip(public_key: PublicKey) {
let tempdir = tempfile::tempdir().unwrap();
let path = tempdir.path().join("test_public_key.pem");
Expand Down Expand Up @@ -214,6 +216,7 @@ fn check_ord_and_hash<T: Clone + Ord + PartialOrd + Hash>(low: T, high: T) {
}

mod system {
#[cfg(any(feature = "std-fs-io", test))]
use std::path::Path;

use super::{sign, verify};
Expand All @@ -229,6 +232,7 @@ mod system {
assert!(SecretKey::system().to_pem().is_err());
}

#[cfg(any(feature = "std-fs-io", test))]
#[test]
fn secret_key_to_file_should_error() {
assert!(SecretKey::system().to_file(Path::new("/dev/null")).is_err());
Expand All @@ -249,6 +253,7 @@ mod system {
assert!(PublicKey::system().to_pem().is_err());
}

#[cfg(any(feature = "std-fs-io", test))]
#[test]
fn public_key_to_file_should_error() {
assert!(PublicKey::system().to_file(Path::new("/dev/null")).is_err());
Expand Down Expand Up @@ -341,6 +346,7 @@ MC4CAQAwBQYDK2VwBCIEINTuctv5E1hK1bbY8fdp+K06/nwoy/HU++CXqI9EdVhC
super::known_secret_key_to_pem(&expected_key, KNOWN_KEY_PEM, ED25519_TAG);
}

#[cfg(any(feature = "std-fs-io", test))]
#[test]
fn secret_key_to_and_from_file() {
let mut rng = TestRng::new();
Expand Down Expand Up @@ -397,6 +403,7 @@ MCowBQYDK2VwAyEAGb9ECWmEzf6FQbrBZ9w7lshQhqowtrbLDFw4rXAxZuE=
super::known_public_key_to_pem(KNOWN_KEY_HEX, KNOWN_KEY_PEM);
}

#[cfg(any(feature = "std-fs-io", test))]
#[test]
fn public_key_to_and_from_file() {
let mut rng = TestRng::new();
Expand Down Expand Up @@ -584,6 +591,7 @@ Yj9oTB9fx9+vvQdxJOhMtu46kGo0Uw==
}

#[test]
#[cfg(any(feature = "std-fs-io", test))]
fn secret_key_to_and_from_file() {
let mut rng = TestRng::new();
let secret_key = SecretKey::random_secp256k1(&mut rng);
Expand Down Expand Up @@ -640,6 +648,7 @@ kv+kBR5u4ISEAkuc2TFWQHX0Yj9oTB9fx9+vvQdxJOhMtu46kGo0Uw==
super::known_public_key_to_pem(KNOWN_KEY_HEX, KNOWN_KEY_PEM);
}

#[cfg(any(feature = "std-fs-io", test))]
#[test]
fn public_key_to_and_from_file() {
let mut rng = TestRng::new();
Expand Down
10 changes: 8 additions & 2 deletions types/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,14 +67,15 @@ mod tagged;
#[cfg(any(feature = "testing", test))]
pub mod testing;
mod timestamp;
mod transaction;
/// Module containing transaction types.
pub mod transaction;
jacek-casper marked this conversation as resolved.
Show resolved Hide resolved
mod transfer;
mod transfer_result;
mod uint;
mod uref;
mod validator_change;

#[cfg(feature = "std")]
#[cfg(all(feature = "std", any(feature = "std-fs-io", test)))]
use libc::{c_long, sysconf, _SC_PAGESIZE};
#[cfg(feature = "std")]
use once_cell::sync::Lazy;
Expand Down Expand Up @@ -223,8 +224,13 @@ pub static OS_PAGE_SIZE: Lazy<usize> = Lazy::new(|| {
/// Sensible default for many if not all systems.
const DEFAULT_PAGE_SIZE: usize = 4096;

#[cfg(any(feature = "std-fs-io", test))]
// https://www.gnu.org/software/libc/manual/html_node/Sysconf.html
let value: c_long = unsafe { sysconf(_SC_PAGESIZE) };

#[cfg(not(any(feature = "std-fs-io", test)))]
let value = 0;

if value <= 0 {
DEFAULT_PAGE_SIZE
} else {
Expand Down
5 changes: 5 additions & 0 deletions types/src/transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -534,6 +534,11 @@ pub mod gens {

use super::*;

/// Generates a random `DeployHash` for testing purposes.
///
/// This function is used to generate random `DeployHash` values for testing purposes.
/// It produces a proptest `Strategy` that can be used to generate arbitrary `DeployHash`
/// values.
pub fn deploy_hash_arb() -> impl Strategy<Value = DeployHash> {
array::uniform32(<u8>::arbitrary()).prop_map(DeployHash::from_raw)
}
Expand Down
7 changes: 6 additions & 1 deletion types/src/transaction/deploy/deploy_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,15 @@ impl<'a> DeployBuilder<'a> {
/// [`with_standard_payment`](Self::with_standard_payment) or
/// [`with_payment`](Self::with_payment)
pub fn new<C: Into<String>>(chain_name: C, session: ExecutableDeployItem) -> Self {
#[cfg(any(feature = "std-fs-io", test))]
let timestamp = Timestamp::now();
#[cfg(not(any(feature = "std-fs-io", test)))]
let timestamp = Timestamp::zero();

DeployBuilder {
account: None,
secret_key: None,
timestamp: Timestamp::now(),
timestamp,
ttl: Self::DEFAULT_TTL,
gas_price: Self::DEFAULT_GAS_PRICE,
dependencies: vec![],
Expand Down
7 changes: 6 additions & 1 deletion types/src/transaction/deploy/deploy_hash.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use alloc::vec::Vec;
use alloc::{string::String, vec::Vec};
use core::fmt::{self, Display, Formatter};

#[cfg(feature = "datasize")]
Expand Down Expand Up @@ -45,6 +45,11 @@ impl DeployHash {
&self.0
}

/// Hexadecimal representation of the hash.
pub fn to_hex_string(&self) -> String {
base16::encode_lower(self.inner())
}

/// Returns a new `DeployHash` directly initialized with the provided bytes; no hashing is done.
#[cfg(any(feature = "testing", test))]
pub const fn from_raw(raw_digest: [u8; Self::LENGTH]) -> Self {
Expand Down
Loading
Loading