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:
SwayStar123 2025-03-21 20:54:06 +05:30 committed by GitHub
parent 8c916c80ee
commit 516c999c15
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
16 changed files with 120 additions and 0 deletions

View file

@ -16,6 +16,7 @@ use ::inputs::{
}; };
use ::revert::revert; use ::revert::revert;
use ::vec::Vec; use ::vec::Vec;
use ::codec::*;
/// The error type used when an `Identity` cannot be determined. /// The error type used when an `Identity` cannot be determined.
pub enum AuthError { pub enum AuthError {

View file

@ -6,6 +6,7 @@ use ::result::Result::{self, *};
use ::logging::log; use ::logging::log;
use ::primitives::*; use ::primitives::*;
use ::ops::*; use ::ops::*;
use ::codec::*;
/// Error type for when the block hash cannot be found. /// Error type for when the block hash cannot be found.
pub enum BlockHashError { pub enum BlockHashError {

View file

@ -9,6 +9,7 @@ use ::hash::*;
use ::result::Result::{self, *}; use ::result::Result::{self, *};
use ::option::Option::{self, *}; use ::option::Option::{self, *};
use ::ops::*; use ::ops::*;
use ::codec::*;
/// An ed25519 signature. /// An ed25519 signature.
pub struct Ed25519 { pub struct Ed25519 {

View file

@ -7,6 +7,7 @@ use ::convert::{From, TryFrom, TryInto};
use ::option::Option::{self, *}; use ::option::Option::{self, *};
use ::hash::*; use ::hash::*;
use ::ops::*; use ::ops::*;
use ::codec::*;
/// Normalized (hashed) message authenticated by a signature. /// Normalized (hashed) message authenticated by a signature.
pub struct Message { pub struct Message {

View file

@ -5,6 +5,7 @@ use ::bytes::{Bytes, *};
use ::option::Option::{self, *}; use ::option::Option::{self, *};
use ::ops::*; use ::ops::*;
use ::primitive_conversions::u256::*; use ::primitive_conversions::u256::*;
use ::codec::*;
// NOTE: Bytes are used to support numbers greater than 32 bytes for future curves. // NOTE: Bytes are used to support numbers greater than 32 bytes for future curves.
/// A 2D point on a field. /// A 2D point on a field.

View file

@ -8,6 +8,7 @@ use ::convert::{From, TryFrom, TryInto};
use ::option::Option::{self, *}; use ::option::Option::{self, *};
use ::hash::*; use ::hash::*;
use ::ops::*; use ::ops::*;
use ::codec::*;
/// Asymmetric public key, i.e. verifying key, in uncompressed form. /// Asymmetric public key, i.e. verifying key, in uncompressed form.
/// ///

View file

@ -5,6 +5,7 @@ use ::bytes::{Bytes, *};
use ::option::Option::{self, *}; use ::option::Option::{self, *};
use ::ops::*; use ::ops::*;
use ::primitive_conversions::u256::*; use ::primitive_conversions::u256::*;
use ::codec::*;
// NOTE: Bytes are used to support numbers greater than 32 bytes for future curves. // NOTE: Bytes are used to support numbers greater than 32 bytes for future curves.
/// The Scalar type used in cryptographic operations. /// The Scalar type used in cryptographic operations.

View file

@ -12,6 +12,8 @@ use ::result::Result::{self, *};
use ::option::Option::{self, *}; use ::option::Option::{self, *};
use ::vm::evm::evm_address::EvmAddress; use ::vm::evm::evm_address::EvmAddress;
use ::ops::*; use ::ops::*;
use ::codec::*;
/// A secp256k1 signature. /// A secp256k1 signature.
pub struct Secp256k1 { pub struct Secp256k1 {
/// The underlying raw `[u8; 64]` data of the signature. /// The underlying raw `[u8; 64]` data of the signature.

View file

@ -12,6 +12,8 @@ use ::result::Result::{self, *};
use ::option::Option::{self, *}; use ::option::Option::{self, *};
use ::vm::evm::evm_address::EvmAddress; use ::vm::evm::evm_address::EvmAddress;
use ::ops::*; use ::ops::*;
use ::codec::*;
/// A secp256r1 signature. /// A secp256r1 signature.
pub struct Secp256r1 { pub struct Secp256r1 {
/// The underlying raw `[u8; 64]` data of the signature. /// The underlying raw `[u8; 64]` data of the signature.

View file

@ -12,6 +12,7 @@ use ::crypto::{
use ::option::Option::{self, *}; use ::option::Option::{self, *};
use ::result::Result::{self, *}; use ::result::Result::{self, *};
use ::vm::evm::evm_address::EvmAddress; use ::vm::evm::evm_address::EvmAddress;
use ::codec::*;
/// An ECDSA signature. /// An ECDSA signature.
pub enum Signature { pub enum Signature {

View file

@ -1,5 +1,7 @@
library; library;
use ::codec::*;
/// The error type used when a cryptographic signature function fails. /// The error type used when a cryptographic signature function fails.
pub enum SignatureError { pub enum SignatureError {
/// The error variant used when the recover fails. /// The error variant used when the recover fails.

View file

@ -7,6 +7,7 @@ use ::bytes::Bytes;
use ::registers::error; use ::registers::error;
use ::hash::*; use ::hash::*;
use ::result::Result::{self, *}; use ::result::Result::{self, *};
use ::codec::*;
/// The error type used when the `ec_recover` function fails. /// The error type used when the `ec_recover` function fails.
pub enum EcRecoverError { pub enum EcRecoverError {

View file

@ -3,6 +3,7 @@ library;
use ::alloc::alloc_bytes; use ::alloc::alloc_bytes;
use ::bytes::*; use ::bytes::*;
use ::codec::*;
pub struct Hasher { pub struct Hasher {
bytes: Bytes, bytes: Bytes,

View file

@ -8,6 +8,7 @@ members = [
"test_programs/b512_inline_tests", "test_programs/b512_inline_tests",
"test_programs/block_inline_tests", "test_programs/block_inline_tests",
"test_programs/bytes_inline_tests", "test_programs/bytes_inline_tests",
"test_programs/codec_implemented_tests",
"test_programs/contract_id_inline_tests", "test_programs/contract_id_inline_tests",
"test_programs/contract_id_contract_tests", "test_programs/contract_id_contract_tests",
"test_programs/crypto_point2d_inline_tests", "test_programs/crypto_point2d_inline_tests",

View file

@ -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" }

View file

@ -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());
}