mirror of
https://github.com/FuelLabs/sway.git
synced 2025-08-21 02:50:47 +00:00
Import codec to all files that define new types in std lib (#7028)
## Description Codec needs to be imported to all libraries in the std lib which define new types, or else they cannot be used in Abi functions or logged. ## Checklist - [ ] I have linked to any relevant issues. - [ ] I have commented my code, particularly in hard-to-understand areas. - [ ] I have updated the documentation where relevant (API docs, the reference, and the Sway book). - [ ] If my change requires substantial documentation changes, I have [requested support from the DevRel team](https://github.com/FuelLabs/devrel-requests/issues/new/choose) - [ ] I have added tests that prove my fix is effective or that my feature works. - [ ] I have added (or requested a maintainer to add) the necessary `Breaking*` or `New Feature` labels where relevant. - [ ] I have done my best to ensure that my PR adheres to [the Fuel Labs Code Review Standards](https://github.com/FuelLabs/rfcs/blob/master/text/code-standards/external-contributors.md). - [ ] I have requested a review from the relevant team or maintainers. --------- Co-authored-by: K1-R1 <77465250+K1-R1@users.noreply.github.com>
This commit is contained in:
parent
8c916c80ee
commit
516c999c15
16 changed files with 120 additions and 0 deletions
|
@ -16,6 +16,7 @@ use ::inputs::{
|
|||
};
|
||||
use ::revert::revert;
|
||||
use ::vec::Vec;
|
||||
use ::codec::*;
|
||||
|
||||
/// The error type used when an `Identity` cannot be determined.
|
||||
pub enum AuthError {
|
||||
|
|
|
@ -6,6 +6,7 @@ use ::result::Result::{self, *};
|
|||
use ::logging::log;
|
||||
use ::primitives::*;
|
||||
use ::ops::*;
|
||||
use ::codec::*;
|
||||
|
||||
/// Error type for when the block hash cannot be found.
|
||||
pub enum BlockHashError {
|
||||
|
|
|
@ -9,6 +9,7 @@ use ::hash::*;
|
|||
use ::result::Result::{self, *};
|
||||
use ::option::Option::{self, *};
|
||||
use ::ops::*;
|
||||
use ::codec::*;
|
||||
|
||||
/// An ed25519 signature.
|
||||
pub struct Ed25519 {
|
||||
|
|
|
@ -7,6 +7,7 @@ use ::convert::{From, TryFrom, TryInto};
|
|||
use ::option::Option::{self, *};
|
||||
use ::hash::*;
|
||||
use ::ops::*;
|
||||
use ::codec::*;
|
||||
|
||||
/// Normalized (hashed) message authenticated by a signature.
|
||||
pub struct Message {
|
||||
|
|
|
@ -5,6 +5,7 @@ use ::bytes::{Bytes, *};
|
|||
use ::option::Option::{self, *};
|
||||
use ::ops::*;
|
||||
use ::primitive_conversions::u256::*;
|
||||
use ::codec::*;
|
||||
|
||||
// NOTE: Bytes are used to support numbers greater than 32 bytes for future curves.
|
||||
/// A 2D point on a field.
|
||||
|
|
|
@ -8,6 +8,7 @@ use ::convert::{From, TryFrom, TryInto};
|
|||
use ::option::Option::{self, *};
|
||||
use ::hash::*;
|
||||
use ::ops::*;
|
||||
use ::codec::*;
|
||||
|
||||
/// Asymmetric public key, i.e. verifying key, in uncompressed form.
|
||||
///
|
||||
|
|
|
@ -5,6 +5,7 @@ use ::bytes::{Bytes, *};
|
|||
use ::option::Option::{self, *};
|
||||
use ::ops::*;
|
||||
use ::primitive_conversions::u256::*;
|
||||
use ::codec::*;
|
||||
|
||||
// NOTE: Bytes are used to support numbers greater than 32 bytes for future curves.
|
||||
/// The Scalar type used in cryptographic operations.
|
||||
|
|
|
@ -12,6 +12,8 @@ use ::result::Result::{self, *};
|
|||
use ::option::Option::{self, *};
|
||||
use ::vm::evm::evm_address::EvmAddress;
|
||||
use ::ops::*;
|
||||
use ::codec::*;
|
||||
|
||||
/// A secp256k1 signature.
|
||||
pub struct Secp256k1 {
|
||||
/// The underlying raw `[u8; 64]` data of the signature.
|
||||
|
|
|
@ -12,6 +12,8 @@ use ::result::Result::{self, *};
|
|||
use ::option::Option::{self, *};
|
||||
use ::vm::evm::evm_address::EvmAddress;
|
||||
use ::ops::*;
|
||||
use ::codec::*;
|
||||
|
||||
/// A secp256r1 signature.
|
||||
pub struct Secp256r1 {
|
||||
/// The underlying raw `[u8; 64]` data of the signature.
|
||||
|
|
|
@ -12,6 +12,7 @@ use ::crypto::{
|
|||
use ::option::Option::{self, *};
|
||||
use ::result::Result::{self, *};
|
||||
use ::vm::evm::evm_address::EvmAddress;
|
||||
use ::codec::*;
|
||||
|
||||
/// An ECDSA signature.
|
||||
pub enum Signature {
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
library;
|
||||
|
||||
use ::codec::*;
|
||||
|
||||
/// The error type used when a cryptographic signature function fails.
|
||||
pub enum SignatureError {
|
||||
/// The error variant used when the recover fails.
|
||||
|
|
|
@ -7,6 +7,7 @@ use ::bytes::Bytes;
|
|||
use ::registers::error;
|
||||
use ::hash::*;
|
||||
use ::result::Result::{self, *};
|
||||
use ::codec::*;
|
||||
|
||||
/// The error type used when the `ec_recover` function fails.
|
||||
pub enum EcRecoverError {
|
||||
|
|
|
@ -3,6 +3,7 @@ library;
|
|||
|
||||
use ::alloc::alloc_bytes;
|
||||
use ::bytes::*;
|
||||
use ::codec::*;
|
||||
|
||||
pub struct Hasher {
|
||||
bytes: Bytes,
|
||||
|
|
|
@ -8,6 +8,7 @@ members = [
|
|||
"test_programs/b512_inline_tests",
|
||||
"test_programs/block_inline_tests",
|
||||
"test_programs/bytes_inline_tests",
|
||||
"test_programs/codec_implemented_tests",
|
||||
"test_programs/contract_id_inline_tests",
|
||||
"test_programs/contract_id_contract_tests",
|
||||
"test_programs/crypto_point2d_inline_tests",
|
||||
|
|
|
@ -0,0 +1,8 @@
|
|||
[project]
|
||||
authors = ["Fuel Labs <contact@fuel.sh>"]
|
||||
entry = "main.sw"
|
||||
license = "Apache-2.0"
|
||||
name = "codec_implemented_tests"
|
||||
|
||||
[dependencies]
|
||||
std = { path = "../../../../../sway-lib-std" }
|
|
@ -0,0 +1,95 @@
|
|||
library;
|
||||
// Logs every new type defined in the std lib to ensure codec is working for them
|
||||
|
||||
use std::{
|
||||
logging::log,
|
||||
address::Address,
|
||||
bytes::{
|
||||
Bytes
|
||||
},
|
||||
crypto::{
|
||||
alt_bn128::AltBn128Error,
|
||||
ed25519::Ed25519,
|
||||
message::Message,
|
||||
point2d::Point2D,
|
||||
public_key::PublicKey,
|
||||
scalar::Scalar,
|
||||
secp256k1::Secp256k1,
|
||||
secp256r1::Secp256r1,
|
||||
signature_error::SignatureError,
|
||||
signature::Signature,
|
||||
},
|
||||
storage::{
|
||||
storage_bytes::StorageBytes,
|
||||
storage_key::StorageKey,
|
||||
storage_string::StorageString,
|
||||
storage_vec::StorageVec,
|
||||
},
|
||||
vm::evm::evm_address::EvmAddress,
|
||||
alias::SubId,
|
||||
asset_id::AssetId,
|
||||
auth::AuthError,
|
||||
b512::B512,
|
||||
block::BlockHashError,
|
||||
contract_id::ContractId,
|
||||
ecr::EcRecoverError,
|
||||
hash::Hasher,
|
||||
identity::Identity,
|
||||
inputs::Input,
|
||||
low_level_call::CallParams,
|
||||
option::Option,
|
||||
outputs::Output,
|
||||
result::Result,
|
||||
string::String,
|
||||
tx::Transaction,
|
||||
u128::U128,
|
||||
vec::{
|
||||
Vec
|
||||
},
|
||||
};
|
||||
|
||||
|
||||
#[test]
|
||||
fn test_logging() {
|
||||
log(Address::zero());
|
||||
log(Bytes::new());
|
||||
log(AltBn128Error::InvalidEllipticCurvePoint);
|
||||
log(Ed25519::new());
|
||||
log(Message::new());
|
||||
log(Point2D::new());
|
||||
log(PublicKey::new());
|
||||
log(Scalar::new());
|
||||
log(Secp256k1::new());
|
||||
log(Secp256r1::new());
|
||||
log(SignatureError::UnrecoverablePublicKey);
|
||||
log(Signature::Secp256k1(Secp256k1::new()));
|
||||
log(StorageBytes {});
|
||||
let skey: StorageKey<u64> = StorageKey::new(b256::zero(), 0, b256::zero());
|
||||
log(skey);
|
||||
let smap: StorageMap<u64, u64> = StorageMap {};
|
||||
log(smap);
|
||||
log(StorageString {});
|
||||
let svec: StorageVec<u64> = StorageVec {};
|
||||
log(svec);
|
||||
log(EvmAddress::zero());
|
||||
log(SubId::zero());
|
||||
log(Vec::<u64>::new());
|
||||
log(AssetId::zero());
|
||||
log(AuthError::CallerIsInternal);
|
||||
log(B512::zero());
|
||||
log(BlockHashError::BlockHeightTooHigh);
|
||||
log(ContractId::zero());
|
||||
log(EcRecoverError::UnrecoverablePublicKey);
|
||||
log(Hasher::new());
|
||||
log(Identity::Address(Address::zero()));
|
||||
log(Input::Coin);
|
||||
log(CallParams{coins: 0, asset_id: AssetId::zero(), gas: 0});
|
||||
let option: Option<u64> = Option::Some(0);
|
||||
log(option);
|
||||
log(Output::Coin);
|
||||
let res: Result<u64, u64> = Result::Ok(0);
|
||||
log(res);
|
||||
log(String::new());
|
||||
log(Transaction::Script);
|
||||
log(U128::zero());
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue