Skip to content

Commit

Permalink
[compiler-v2] fixed all unittest errors after modify address format (#…
Browse files Browse the repository at this point in the history
…4343)

* [compiler-v2 framework] fixed known_attribute warning in `mpm package test ` command

* [compiler-v2 framework] fixed known_attribute warning in `mpm package test ` command

* [compiler-v2 framework] remove unused code

* [compiler-v2 framework] fixed stderr after 0x1 changed

* [compiler-v2 framework] fixed error caused by address format changed

* [compiler-v2 framework] fixed fmt

* [compiler-v2 framework] Remove starcoin-framework from the nextest exclude list

---------

Co-authored-by: nk_ysg <nk_ysg@163.com>
  • Loading branch information
welbon and nkysg authored Dec 13, 2024
1 parent f13c92c commit db3cd34
Show file tree
Hide file tree
Showing 10 changed files with 119 additions and 81 deletions.
1 change: 0 additions & 1 deletion scripts/nextest.sh
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ cargo nextest -V >/dev/null 2>&1 || cargo install cargo-nextest --version "0.9.5
# --build-jobs 8, a little (~20s) faster than 5 or 10 build jobs
cargo nextest run --workspace \
--exclude starcoin-transactional-test-harness \
--exclude starcoin-framework \
--exclude starcoin-consensus \
--retries 2 --build-jobs 8 --test-threads 12 --no-fail-fast --failure-output immediate-final

Expand Down
96 changes: 63 additions & 33 deletions vm/framework/src/natives/cryptography/algebra/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,18 +71,20 @@ impl TryFrom<TypeTag> for Structure {

fn try_from(value: TypeTag) -> Result<Self, Self::Error> {
match value.to_string().as_str() {
"0x1::bls12381_algebra::Fr" => Ok(Structure::BLS12381Fr),
"0x1::bls12381_algebra::Fq12" => Ok(Structure::BLS12381Fq12),
"0x1::bls12381_algebra::G1" => Ok(Structure::BLS12381G1),
"0x1::bls12381_algebra::G2" => Ok(Structure::BLS12381G2),
"0x1::bls12381_algebra::Gt" => Ok(Structure::BLS12381Gt),

"0x1::bn254_algebra::Fr" => Ok(Self::BN254Fr),
"0x1::bn254_algebra::Fq" => Ok(Self::BN254Fq),
"0x1::bn254_algebra::Fq12" => Ok(Self::BN254Fq12),
"0x1::bn254_algebra::G1" => Ok(Self::BN254G1),
"0x1::bn254_algebra::G2" => Ok(Self::BN254G2),
"0x1::bn254_algebra::Gt" => Ok(Self::BN254Gt),
"0x00000000000000000000000000000001::bls12381_algebra::Fr" => Ok(Structure::BLS12381Fr),
"0x00000000000000000000000000000001::bls12381_algebra::Fq12" => {
Ok(Structure::BLS12381Fq12)
}
"0x00000000000000000000000000000001::bls12381_algebra::G1" => Ok(Structure::BLS12381G1),
"0x00000000000000000000000000000001::bls12381_algebra::G2" => Ok(Structure::BLS12381G2),
"0x00000000000000000000000000000001::bls12381_algebra::Gt" => Ok(Structure::BLS12381Gt),

"0x00000000000000000000000000000001::bn254_algebra::Fr" => Ok(Self::BN254Fr),
"0x00000000000000000000000000000001::bn254_algebra::Fq" => Ok(Self::BN254Fq),
"0x00000000000000000000000000000001::bn254_algebra::Fq12" => Ok(Self::BN254Fq12),
"0x00000000000000000000000000000001::bn254_algebra::G1" => Ok(Self::BN254G1),
"0x00000000000000000000000000000001::bn254_algebra::G2" => Ok(Self::BN254G2),
"0x00000000000000000000000000000001::bn254_algebra::Gt" => Ok(Self::BN254Gt),
_ => Err(()),
}
}
Expand Down Expand Up @@ -125,31 +127,59 @@ impl TryFrom<TypeTag> for SerializationFormat {

fn try_from(value: TypeTag) -> Result<Self, Self::Error> {
match value.to_string().as_str() {
"0x1::bls12381_algebra::FormatFq12LscLsb" => {
"0x00000000000000000000000000000001::bls12381_algebra::FormatFq12LscLsb" => {
Ok(SerializationFormat::BLS12381Fq12LscLsb)
}
"0x1::bls12381_algebra::FormatG1Uncompr" => {
"0x00000000000000000000000000000001::bls12381_algebra::FormatG1Uncompr" => {
Ok(SerializationFormat::BLS12381G1Uncompressed)
}
"0x1::bls12381_algebra::FormatG1Compr" => Ok(SerializationFormat::BLS12381G1Compressed),
"0x1::bls12381_algebra::FormatG2Uncompr" => {
"0x00000000000000000000000000000001::bls12381_algebra::FormatG1Compr" => {
Ok(SerializationFormat::BLS12381G1Compressed)
}
"0x00000000000000000000000000000001::bls12381_algebra::FormatG2Uncompr" => {
Ok(SerializationFormat::BLS12381G2Uncompressed)
}
"0x1::bls12381_algebra::FormatG2Compr" => Ok(SerializationFormat::BLS12381G2Compressed),
"0x1::bls12381_algebra::FormatGt" => Ok(SerializationFormat::BLS12381Gt),
"0x1::bls12381_algebra::FormatFrLsb" => Ok(SerializationFormat::BLS12381FrLsb),
"0x1::bls12381_algebra::FormatFrMsb" => Ok(SerializationFormat::BLS12381FrMsb),

"0x1::bn254_algebra::FormatG1Uncompr" => Ok(Self::BN254G1Uncompressed),
"0x1::bn254_algebra::FormatG1Compr" => Ok(Self::BN254G1Compressed),
"0x1::bn254_algebra::FormatG2Uncompr" => Ok(Self::BN254G2Uncompressed),
"0x1::bn254_algebra::FormatG2Compr" => Ok(Self::BN254G2Compressed),
"0x1::bn254_algebra::FormatGt" => Ok(Self::BN254Gt),
"0x1::bn254_algebra::FormatFrLsb" => Ok(Self::BN254FrLsb),
"0x1::bn254_algebra::FormatFrMsb" => Ok(Self::BN254FrMsb),
"0x1::bn254_algebra::FormatFqLsb" => Ok(Self::BN254FqLsb),
"0x1::bn254_algebra::FormatFqMsb" => Ok(Self::BN254FqMsb),
"0x1::bn254_algebra::FormatFq12LscLsb" => Ok(Self::BN254Fq12LscLsb),
"0x00000000000000000000000000000001::bls12381_algebra::FormatG2Compr" => {
Ok(SerializationFormat::BLS12381G2Compressed)
}
"0x00000000000000000000000000000001::bls12381_algebra::FormatGt" => {
Ok(SerializationFormat::BLS12381Gt)
}
"0x00000000000000000000000000000001::bls12381_algebra::FormatFrLsb" => {
Ok(SerializationFormat::BLS12381FrLsb)
}
"0x00000000000000000000000000000001::bls12381_algebra::FormatFrMsb" => {
Ok(SerializationFormat::BLS12381FrMsb)
}

"0x00000000000000000000000000000001::bn254_algebra::FormatG1Uncompr" => {
Ok(Self::BN254G1Uncompressed)
}
"0x00000000000000000000000000000001::bn254_algebra::FormatG1Compr" => {
Ok(Self::BN254G1Compressed)
}
"0x00000000000000000000000000000001::bn254_algebra::FormatG2Uncompr" => {
Ok(Self::BN254G2Uncompressed)
}
"0x00000000000000000000000000000001::bn254_algebra::FormatG2Compr" => {
Ok(Self::BN254G2Compressed)
}
"0x00000000000000000000000000000001::bn254_algebra::FormatGt" => Ok(Self::BN254Gt),
"0x00000000000000000000000000000001::bn254_algebra::FormatFrLsb" => {
Ok(Self::BN254FrLsb)
}
"0x00000000000000000000000000000001::bn254_algebra::FormatFrMsb" => {
Ok(Self::BN254FrMsb)
}
"0x00000000000000000000000000000001::bn254_algebra::FormatFqLsb" => {
Ok(Self::BN254FqLsb)
}
"0x00000000000000000000000000000001::bn254_algebra::FormatFqMsb" => {
Ok(Self::BN254FqMsb)
}
"0x00000000000000000000000000000001::bn254_algebra::FormatFq12LscLsb" => {
Ok(Self::BN254Fq12LscLsb)
}
_ => Err(()),
}
}
Expand All @@ -167,10 +197,10 @@ impl TryFrom<TypeTag> for HashToStructureSuite {

fn try_from(value: TypeTag) -> Result<Self, Self::Error> {
match value.to_string().as_str() {
"0x1::bls12381_algebra::HashG1XmdSha256SswuRo" => {
"0x00000000000000000000000000000001::bls12381_algebra::HashG1XmdSha256SswuRo" => {
Ok(HashToStructureSuite::Bls12381g1XmdSha256SswuRo)
}
"0x1::bls12381_algebra::HashG2XmdSha256SswuRo" => {
"0x00000000000000000000000000000001::bls12381_algebra::HashG2XmdSha256SswuRo" => {
Ok(HashToStructureSuite::Bls12381g2XmdSha256SswuRo)
}
_ => Err(()),
Expand Down
4 changes: 2 additions & 2 deletions vm/framework/starcoin-stdlib/doc/type_info.md
Original file line number Diff line number Diff line change
Expand Up @@ -218,8 +218,8 @@ Return the <code><a href="type_info.md#0x1_type_info_TypeInfo">TypeInfo</a></cod
## Function `type_name`

Return the human readable string for the type, including the address, module name, and any type arguments.
Example: 0x1::coin::CoinStore<0x1::aptos_coin::AptosCoin>
Or: 0x1::table::Table<0x1::string::String, 0x1::string::String>
Example: 0x00000000000000000000000000000001::coin::CoinStore<0x00000000000000000000000000000001::aptos_coin::AptosCoin>
Or: 0x00000000000000000000000000000001::table::Table<0x00000000000000000000000000000001::string::String, 0x00000000000000000000000000000001::string::String>


<pre><code><b>public</b> <b>fun</b> <a href="type_info.md#0x1_type_info_type_name">type_name</a>&lt;T&gt;(): <a href="../../move-stdlib/doc/string.md#0x1_string_String">string::String</a>
Expand Down
19 changes: 9 additions & 10 deletions vm/framework/starcoin-stdlib/sources/debug.move
Original file line number Diff line number Diff line change
Expand Up @@ -74,13 +74,13 @@ module starcoin_std::debug {
assert_equal(&v, b"[ 100, 200, 300 ]");

let foo = Foo {};
assert_equal(&foo, b"0x1::debug::Foo {\n dummy_field: false\n}");
assert_equal(&foo, b"0x00000000000000000000000000000001::debug::Foo {\n dummy_field: false\n}");

let bar = Bar { x: 404, y: Foo {}, z: true };
assert_equal(&bar, b"0x1::debug::Bar {\n x: 404,\n y: 0x1::debug::Foo {\n dummy_field: false\n },\n z: true\n}");
assert_equal(&bar, b"0x00000000000000000000000000000001::debug::Bar {\n x: 404,\n y: 0x00000000000000000000000000000001::debug::Foo {\n dummy_field: false\n },\n z: true\n}");

let box = Box { x: Foo {} };
assert_equal(&box, b"0x1::debug::Box<0x1::debug::Foo> {\n x: 0x1::debug::Foo {\n dummy_field: false\n }\n}");
assert_equal(&box, b"0x00000000000000000000000000000001::debug::Box<0x00000000000000000000000000000001::debug::Foo> {\n x: 0x00000000000000000000000000000001::debug::Foo {\n dummy_field: false\n }\n}");
}

#[test]
Expand Down Expand Up @@ -155,15 +155,15 @@ module starcoin_std::debug {
msgs: vector[MSG_1, MSG_2],
};

assert_equal(&obj, b"0x1::debug::TestInner {\n val: 100,\n vec: [ 200, 400 ],\n msgs: [\n 0x616263646566,\n 0x313233343536\n ]\n}");
assert_equal(&obj, b"0x00000000000000000000000000000001::debug::TestInner {\n val: 100,\n vec: [ 200, 400 ],\n msgs: [\n 0x616263646566,\n 0x313233343536\n ]\n}");

let obj = TestInner {
val: 10,
vec: vector[],
msgs: vector[],
};

assert_equal(&obj, b"0x1::debug::TestInner {\n val: 10,\n vec: [],\n msgs: []\n}");
assert_equal(&obj, b"0x00000000000000000000000000000001::debug::TestInner {\n val: 10,\n vec: [],\n msgs: []\n}");
}

#[test(_s1 = @0x123, _s2 = @0x456)]
Expand Down Expand Up @@ -210,7 +210,7 @@ module starcoin_std::debug {
msgs: vector[x"0000"],
}
];
assert_equal(&v, b"[\n 0x1::debug::TestInner {\n val: 4,\n vec: [ 127, 128 ],\n msgs: [\n 0x00ff,\n 0xabcd\n ]\n },\n 0x1::debug::TestInner {\n val: 8,\n vec: [ 128, 129 ],\n msgs: [\n 0x0000\n ]\n }\n]");
assert_equal(&v, b"[\n 0x00000000000000000000000000000001::debug::TestInner {\n val: 4,\n vec: [ 127, 128 ],\n msgs: [\n 0x00ff,\n 0xabcd\n ]\n },\n 0x00000000000000000000000000000001::debug::TestInner {\n val: 8,\n vec: [ 128, 129 ],\n msgs: [\n 0x0000\n ]\n }\n]");
}

#[test(_s1 = @0x123, _s2 = @0x456)]
Expand Down Expand Up @@ -255,7 +255,7 @@ module starcoin_std::debug {
TestInner { val: 8u128 , vec: vector[128u128, 129u128], msgs: vector[] }
]
];
assert_equal(&v, b"[\n [\n 0x1::debug::TestInner {\n val: 4,\n vec: [ 127, 128 ],\n msgs: []\n },\n 0x1::debug::TestInner {\n val: 8,\n vec: [ 128, 129 ],\n msgs: []\n }\n ],\n [\n 0x1::debug::TestInner {\n val: 4,\n vec: [ 127, 128 ],\n msgs: []\n },\n 0x1::debug::TestInner {\n val: 8,\n vec: [ 128, 129 ],\n msgs: []\n }\n ]\n]");
assert_equal(&v, b"[\n [\n 0x00000000000000000000000000000001::debug::TestInner {\n val: 4,\n vec: [ 127, 128 ],\n msgs: []\n },\n 0x00000000000000000000000000000001::debug::TestInner {\n val: 8,\n vec: [ 128, 129 ],\n msgs: []\n }\n ],\n [\n 0x00000000000000000000000000000001::debug::TestInner {\n val: 4,\n vec: [ 127, 128 ],\n msgs: []\n },\n 0x00000000000000000000000000000001::debug::TestInner {\n val: 8,\n vec: [ 128, 129 ],\n msgs: []\n }\n ]\n]");
}

#[test]
Expand All @@ -270,8 +270,7 @@ module starcoin_std::debug {
TestInner { val: 2, vec: vector[132u128, 133u128], msgs: vector[] }
],
};

assert_equal(&obj, b"0x1::debug::TestStruct {\n addr: @0x1,\n number: 255,\n bytes: 0xc0ffee,\n name: \"He\\\"llo\",\n vec: [\n 0x1::debug::TestInner {\n val: 1,\n vec: [ 130, 131 ],\n msgs: []\n },\n 0x1::debug::TestInner {\n val: 2,\n vec: [ 132, 133 ],\n msgs: []\n }\n ]\n}");
assert_equal(&obj, b"0x00000000000000000000000000000001::debug::TestStruct {\n addr: @0x1,\n number: 255,\n bytes: 0xc0ffee,\n name: \"He\\\"llo\",\n vec: [\n 0x00000000000000000000000000000001::debug::TestInner {\n val: 1,\n vec: [ 130, 131 ],\n msgs: []\n },\n 0x00000000000000000000000000000001::debug::TestInner {\n val: 2,\n vec: [ 132, 133 ],\n msgs: []\n }\n ]\n}");
}

#[test]
Expand All @@ -280,6 +279,6 @@ module starcoin_std::debug {
val: 60u64,
};

assert_equal(&obj, b"0x1::debug::GenericStruct<0x1::debug::Foo> {\n val: 60\n}");
assert_equal(&obj, b"0x00000000000000000000000000000001::debug::GenericStruct<0x00000000000000000000000000000001::debug::Foo> {\n val: 60\n}");
}
}
3 changes: 0 additions & 3 deletions vm/framework/starcoin-stdlib/sources/from_bcs.move
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,6 @@ module starcoin_std::from_bcs {
#[test_only]
use std::bcs;

#[test_only]
use std::debug;

#[test]
fun test_address() {
let addr = @0x01;
Expand Down
12 changes: 6 additions & 6 deletions vm/framework/starcoin-stdlib/sources/type_info.move
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ module starcoin_std::type_info {
public native fun type_of<T>(): TypeInfo;

/// Return the human readable string for the type, including the address, module name, and any type arguments.
/// Example: 0x1::coin::CoinStore<0x1::aptos_coin::AptosCoin>
/// Or: 0x1::table::Table<0x1::string::String, 0x1::string::String>
/// Example: 0x00000000000000000000000000000001::coin::CoinStore<0x00000000000000000000000000000001::aptos_coin::AptosCoin>
/// Or: 0x00000000000000000000000000000001::table::Table<0x00000000000000000000000000000001::string::String, 0x00000000000000000000000000000001::string::String>
public native fun type_name<T>(): String;

native fun chain_id_internal(): u8;
Expand Down Expand Up @@ -85,7 +85,7 @@ module starcoin_std::type_info {
let type_info = type_of<Table<String, String>>();
assert!(account_address(&type_info) == @starcoin_std, 0);
assert!(module_name(&type_info) == b"table", 1);
assert!(struct_name(&type_info) == b"Table<0x1::string::String, 0x1::string::String>", 2);
assert!(struct_name(&type_info) == b"Table<0x00000000000000000000000000000001::string::String, 0x00000000000000000000000000000001::string::String>", 2);
}

#[test(fx = @std)]
Expand Down Expand Up @@ -114,17 +114,17 @@ module starcoin_std::type_info {
// vector
assert!(type_name<vector<u8>>() == string::utf8(b"vector<u8>"), 6);
assert!(type_name<vector<vector<u8>>>() == string::utf8(b"vector<vector<u8>>"), 7);
assert!(type_name<vector<vector<TypeInfo>>>() == string::utf8(b"vector<vector<0x1::type_info::TypeInfo>>"), 8);
assert!(type_name<vector<vector<TypeInfo>>>() == string::utf8(b"vector<vector<0x00000000000000000000000000000001::type_info::TypeInfo>>"), 8);


// struct
assert!(type_name<TypeInfo>() == string::utf8(b"0x1::type_info::TypeInfo"), 9);
assert!(type_name<TypeInfo>() == string::utf8(b"0x00000000000000000000000000000001::type_info::TypeInfo"), 9);
assert!(type_name<
Table<
TypeInfo,
Table<u8, vector<TypeInfo>>
>
>() == string::utf8(b"0x1::table::Table<0x1::type_info::TypeInfo, 0x1::table::Table<u8, vector<0x1::type_info::TypeInfo>>>"), 10);
>() == string::utf8(b"0x00000000000000000000000000000001::table::Table<0x00000000000000000000000000000001::type_info::TypeInfo, 0x00000000000000000000000000000001::table::Table<u8, vector<0x00000000000000000000000000000001::type_info::TypeInfo>>>"), 10);
}

#[verify_only]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -507,7 +507,7 @@ Maps <code>String</code> representation of types from their <code>u8</code> repr
} <b>else</b> <b>if</b> (type == <a href="object_property_map.md#0x1_object_property_map_BYTE_VECTOR">BYTE_VECTOR</a>) {
<a href="../../move-stdlib/doc/string.md#0x1_string_utf8">string::utf8</a>(b"<a href="../../move-stdlib/doc/vector.md#0x1_vector">vector</a>&lt;u8&gt;")
} <b>else</b> <b>if</b> (type == <a href="object_property_map.md#0x1_object_property_map_STRING">STRING</a>) {
<a href="../../move-stdlib/doc/string.md#0x1_string_utf8">string::utf8</a>(b"<a href="../../move-stdlib/doc/string.md#0x1_string_String">0x1::string::String</a>")
<a href="../../move-stdlib/doc/string.md#0x1_string_utf8">string::utf8</a>(b"<a href="../../move-stdlib/doc/string.md#0x1_string_String">0x00000000000000000000000000000001::string::String</a>")
} <b>else</b> {
<b>abort</b> (<a href="../../move-stdlib/doc/error.md#0x1_error_invalid_argument">error::invalid_argument</a>(<a href="object_property_map.md#0x1_object_property_map_ETYPE_INVALID">ETYPE_INVALID</a>))
}
Expand Down Expand Up @@ -553,7 +553,7 @@ Maps the <code>String</code> representation of types to <code>u8</code>
<a href="object_property_map.md#0x1_object_property_map_ADDRESS">ADDRESS</a>
} <b>else</b> <b>if</b> (type == <a href="../../move-stdlib/doc/string.md#0x1_string_utf8">string::utf8</a>(b"<a href="../../move-stdlib/doc/vector.md#0x1_vector">vector</a>&lt;u8&gt;")) {
<a href="object_property_map.md#0x1_object_property_map_BYTE_VECTOR">BYTE_VECTOR</a>
} <b>else</b> <b>if</b> (type == <a href="../../move-stdlib/doc/string.md#0x1_string_utf8">string::utf8</a>(b"<a href="../../move-stdlib/doc/string.md#0x1_string_String">0x1::string::String</a>")) {
} <b>else</b> <b>if</b> (type == <a href="../../move-stdlib/doc/string.md#0x1_string_utf8">string::utf8</a>(b"<a href="../../move-stdlib/doc/string.md#0x1_string_String">0x00000000000000000000000000000001::string::String</a>")) {
<a href="object_property_map.md#0x1_object_property_map_STRING">STRING</a>
} <b>else</b> {
<b>abort</b> (<a href="../../move-stdlib/doc/error.md#0x1_error_invalid_argument">error::invalid_argument</a>(<a href="object_property_map.md#0x1_object_property_map_ETYPE_INVALID">ETYPE_INVALID</a>))
Expand Down Expand Up @@ -1268,7 +1268,7 @@ Removes a property from the map, ensuring that it does in fact exist
6
);
<b>assert</b>!(<a href="object_property_map.md#0x1_object_property_map_read_bytes">read_bytes</a>(&<a href="../../starcoin-framework/doc/object.md#0x1_object">object</a>, &<a href="../../move-stdlib/doc/string.md#0x1_string_utf8">string::utf8</a>(b"<a href="../../move-stdlib/doc/vector.md#0x1_vector">vector</a>&lt;u8&gt;")) == <a href="../../move-stdlib/doc/vector.md#0x1_vector">vector</a>[0x01], 7);
<b>assert</b>!(<a href="object_property_map.md#0x1_object_property_map_read_string">read_string</a>(&<a href="../../starcoin-framework/doc/object.md#0x1_object">object</a>, &<a href="../../move-stdlib/doc/string.md#0x1_string_utf8">string::utf8</a>(b"<a href="../../move-stdlib/doc/string.md#0x1_string_String">0x1::string::String</a>")) == <a href="../../move-stdlib/doc/string.md#0x1_string_utf8">string::utf8</a>(b"a"), 8);
<b>assert</b>!(<a href="object_property_map.md#0x1_object_property_map_read_string">read_string</a>(&<a href="../../starcoin-framework/doc/object.md#0x1_object">object</a>, &<a href="../../move-stdlib/doc/string.md#0x1_string_utf8">string::utf8</a>(b"<a href="../../move-stdlib/doc/string.md#0x1_string_String">0x00000000000000000000000000000001::string::String</a>")) == <a href="../../move-stdlib/doc/string.md#0x1_string_utf8">string::utf8</a>(b"a"), 8);

<b>assert</b>!(<a href="object_property_map.md#0x1_object_property_map_length">length</a>(&<a href="../../starcoin-framework/doc/object.md#0x1_object">object</a>) == 9, 9);
}
Expand Down
Loading

0 comments on commit db3cd34

Please sign in to comment.