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

fix: test function for compatibility #119

Merged
merged 17 commits into from
Sep 5, 2024
Binary file modified precompile/binaries/minlib/dex.mv
Binary file not shown.
Binary file modified precompile/binaries/stdlib/dex.mv
Binary file not shown.
Binary file modified precompile/binaries/stdlib/staking.mv
Binary file not shown.
57 changes: 33 additions & 24 deletions precompile/modules/initia_stdlib/sources/account.move
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ module initia_std::account {
account_number: u64,
sequence_number: u64,
account_type: u8,
is_blocked: bool,
is_blocked: bool
}

public entry fun create_account_script(addr: address) {
Expand All @@ -35,7 +35,7 @@ module initia_std::account {
let (found, _, _, _, _) = account_info(addr);
assert!(
!found,
error::already_exists(EACCOUNT_ALREADY_EXISTS),
error::already_exists(EACCOUNT_ALREADY_EXISTS)
);

request_create_account(addr, 0, ACCOUNT_TYPE_BASE)
Expand All @@ -46,15 +46,14 @@ module initia_std::account {
public(friend) fun create_table_account(addr: address): u64 {
let (found, account_number, sequence, account_type, _) = account_info(addr);
assert!(
!found
|| (account_type == ACCOUNT_TYPE_BASE && sequence == 0),
error::already_exists(EACCOUNT_ALREADY_EXISTS),
!found || (account_type == ACCOUNT_TYPE_BASE && sequence == 0),
error::already_exists(EACCOUNT_ALREADY_EXISTS)
);

request_create_account(
addr,
account_number,
ACCOUNT_TYPE_TABLE,
ACCOUNT_TYPE_TABLE
)
}

Expand All @@ -68,7 +67,7 @@ module initia_std::account {
request_create_account(
addr,
account_number,
ACCOUNT_TYPE_OBJECT,
ACCOUNT_TYPE_OBJECT
)
} else {
// When an Object is deleted, the ObjectAccount in CosmosSDK is designed
Expand Down Expand Up @@ -180,8 +179,11 @@ module initia_std::account {
info.sequence_number
}

native fun request_create_account(addr: address, account_number: u64, account_type: u8): u64;
native public fun account_info(addr: address): (
native fun request_create_account(
addr: address, account_number: u64, account_type: u8
): u64;
native public fun account_info(addr: address):
(
bool /* found */,
u64 /* account_number */,
u64 /* sequence_number */,
Expand Down Expand Up @@ -232,7 +234,7 @@ module initia_std::account {
assert!(bob_account_num == get_account_number(bob), 7);
assert!(
carol_account_num == get_account_number(carol),
7,
7
);

// object account
Expand All @@ -244,7 +246,7 @@ module initia_std::account {
let dan_object_account_num = create_object_account(dan);
assert!(
dan_object_account_num == get_account_number(dan),
9,
9
);
assert!(is_object_account(dan), 10);
assert!(exists_at(dan), 11);
Expand All @@ -258,7 +260,7 @@ module initia_std::account {
let erin_table_account_num = create_table_account(erin);
assert!(
erin_table_account_num == get_account_number(erin),
13,
13
);
assert!(is_table_account(erin), 14);
assert!(exists_at(erin), 15);
Expand All @@ -276,11 +278,11 @@ module initia_std::account {
);
assert!(
bob == @0x0000000000000000000000000000000000000000000000000000000000000b0b,
0,
0
);
assert!(
carol == @0x00000000000000000000000000000000000000000000000000000000000ca501,
1,
1
);
}

Expand All @@ -291,17 +293,24 @@ module initia_std::account {
assert!(vector::length(&authentication_key) == 32, 0);
}

#[test(new_address = @0x41, new_address2 = @0x42, new_address3 = @0x43, new_address4 = @0x44)]
#[
test(
new_address = @0x41,
new_address2 = @0x42,
new_address3 = @0x43,
new_address4 = @0x44
)
]
public fun test_create_table_account_and_object_account(
new_address: address,
new_address2: address,
new_address3: address,
new_address4: address,
new_address4: address
) {
let table_account_num = create_table_account(new_address);
assert!(
table_account_num == get_account_number(new_address),
0,
0
);
assert!(is_table_account(new_address), 1);
assert!(exists_at(new_address), 2);
Expand All @@ -312,12 +321,12 @@ module initia_std::account {
100,
0,
ACCOUNT_TYPE_BASE,
false,
false
);
let table_account_num = create_table_account(new_address2);
assert!(
table_account_num == get_account_number(new_address2),
0,
0
);
assert!(table_account_num == 100, 0);
assert!(is_table_account(new_address2), 1);
Expand All @@ -327,7 +336,7 @@ module initia_std::account {
let object_account_num = create_object_account(new_address3);
assert!(
object_account_num == get_account_number(new_address3),
3,
3
);
assert!(is_object_account(new_address3), 4);
assert!(exists_at(new_address3), 5);
Expand All @@ -338,12 +347,12 @@ module initia_std::account {
200,
0,
ACCOUNT_TYPE_BASE,
false,
false
);
let object_account_num = create_object_account(new_address4);
assert!(
object_account_num == get_account_number(new_address4),
0,
0
);
assert!(object_account_num == 200, 0);
assert!(is_object_account(new_address4), 1);
Expand All @@ -360,7 +369,7 @@ module initia_std::account {
200,
0,
ACCOUNT_TYPE_BASE,
true,
true
);
assert!(is_blocked(new_address), 1);

Expand All @@ -369,7 +378,7 @@ module initia_std::account {
100,
0,
ACCOUNT_TYPE_BASE,
false,
false
);
assert!(!is_blocked(new_address2), 2);
}
Expand Down
16 changes: 8 additions & 8 deletions precompile/modules/initia_stdlib/sources/address.move
Original file line number Diff line number Diff line change
Expand Up @@ -6,40 +6,40 @@ module initia_std::address {
use initia_std::json;

struct FromSdkRequest has copy, drop {
sdk_addr: String,
sdk_addr: String
}

struct FromSdkResponse has copy, drop {
vm_addr: address,
vm_addr: address
}

public fun from_sdk(sdk_addr: String): address {
let res =
json::unmarshal<FromSdkResponse>(
query::query_custom(
b"from_sdk_address",
json::marshal(&FromSdkRequest { sdk_addr: sdk_addr, }),
),
json::marshal(&FromSdkRequest { sdk_addr: sdk_addr })
)
);

res.vm_addr
}

struct ToSdkRequest has copy, drop {
vm_addr: address,
vm_addr: address
}

struct ToSdkResponse has copy, drop {
sdk_addr: String,
sdk_addr: String
}

public fun to_sdk(vm_addr: address): String {
let res =
json::unmarshal<ToSdkResponse>(
query::query_custom(
b"to_sdk_address",
json::marshal(&ToSdkRequest { vm_addr: vm_addr, }),
),
json::marshal(&ToSdkRequest { vm_addr: vm_addr })
)
);

res.sdk_addr
Expand Down
7 changes: 5 additions & 2 deletions precompile/modules/initia_stdlib/sources/any.move
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,17 @@ module initia_std::any {
/// Pack a value into the `Any` representation. Because Any can be stored and dropped, this is
/// also required from `T`.
public fun pack<T: drop + store>(x: T): Any {
Any { type_name: type_info::type_name<T>(), data: to_bytes(&x) }
Any {
type_name: type_info::type_name<T>(),
data: to_bytes(&x)
}
}

/// Unpack a value from the `Any` representation. This aborts if the value has not the expected type `T`.
public fun unpack<T>(x: Any): T {
assert!(
type_info::type_name<T>() == x.type_name,
error::invalid_argument(ETYPE_MISMATCH),
error::invalid_argument(ETYPE_MISMATCH)
);
from_bytes<T>(x.data)
}
Expand Down
3 changes: 2 additions & 1 deletion precompile/modules/initia_stdlib/sources/block.move
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ module initia_std::block {
public fun emit_writeset_block_event(
_vm: &signer, _fake_block_hash: address
) {
// no-op
let (block_height, block_time) = get_block_info();
set_block_info(block_height + 1, block_time);
beer-1 marked this conversation as resolved.
Show resolved Hide resolved
}
}
Loading
Loading