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

feat: its tests actual #89

Merged
merged 92 commits into from
Sep 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
92 commits
Select commit Hold shift + click to select a range
7f6cee4
saving progress
Foivos Jun 5, 2024
6e5acdb
Merge remote-tracking branch 'origin/main' into feat/script-utils
Foivos Jun 6, 2024
296eece
added the transaction builder
Foivos Jun 6, 2024
edeeb38
lint and prettier
Foivos Jun 6, 2024
974192d
added object cache
Foivos Jun 7, 2024
5d3543c
fixed some bugs
Foivos Jun 7, 2024
e943312
empty commit
Foivos Jun 7, 2024
9b6be0f
added some structs, adding squid structs next
Foivos Jun 7, 2024
8d623d5
Merge branch 'main' into feat/script-utils
milapsheth Jun 7, 2024
5432896
added all the move types
Foivos Jun 11, 2024
6a8d79b
fix an error
Foivos Jun 11, 2024
36c43a7
prettier
Foivos Jun 11, 2024
8ba2aa9
adding publish options in TxBuilder
Foivos Jun 12, 2024
17600af
fixed some issues after testing
Foivos Jun 14, 2024
fc0acac
add ts of relevant utils
Foivos Jun 14, 2024
0cc49ca
use npx tsc instead
Foivos Jun 17, 2024
6c387bf
run compile properly
Foivos Jun 17, 2024
372514b
remove previous scripts
Foivos Jun 17, 2024
75397e4
add an index.ts
Foivos Jun 17, 2024
89205ae
fix imports
Foivos Jun 17, 2024
59237d4
update bcs pure types
Foivos Jun 17, 2024
cb32ea8
remove last change as it does not work
Foivos Jun 17, 2024
f192b36
add address to bcs
Foivos Jun 17, 2024
517aebb
Merge remote-tracking branch 'origin/main' into feat/script-utils
Foivos Jun 18, 2024
bc6ecc2
shorten typeName calculation as per euro's request
Foivos Jun 18, 2024
1edfffb
prettier
Foivos Jun 18, 2024
4f3aa9e
Merge branch 'feat/script-utils' into feat/bcs-structs
Foivos Jun 18, 2024
46fc8ea
Merge branch 'feat/bcs-structs' into feat/ts
Foivos Jun 18, 2024
8aeee89
add run.sh back
Foivos Jun 18, 2024
4b1dd9c
add coverage.sh back
Foivos Jun 18, 2024
ad10697
get eslint to work
Foivos Jun 18, 2024
4e62c8f
prettier
Foivos Jun 18, 2024
80c6a6c
allow execution of scripts
Foivos Jun 19, 2024
8ab9ed0
stash
Foivos Jun 19, 2024
1cd9f11
stash
Foivos Jun 19, 2024
fb549fa
added deployment test
Foivos Jun 19, 2024
4886636
fix package scripts
Foivos Jun 19, 2024
5774306
prettier and include mocha
Foivos Jun 19, 2024
d0a4879
remove .env dependancy
Foivos Jun 19, 2024
b143ef4
added a test to rotate signers
Foivos Jun 20, 2024
f71d272
Add a revert util and test
Foivos Jun 21, 2024
df94e7e
prettier
Foivos Jun 21, 2024
afc4c9c
run imp i to fix tests
Foivos Jun 21, 2024
8c5f516
added flow limits and scaling all incoming decimals down to 9
Foivos Jun 26, 2024
5b1e687
added proper token handling and helper function for minting/burning a…
Foivos Jun 26, 2024
4e4d73a
Merge remote-tracking branch 'origin/feat/testing' into feat/its-scal…
Foivos Jun 26, 2024
c31fda9
dinished adding all the features for flow limits and decimals convers…
Foivos Jul 1, 2024
b237b8f
add a test file
Foivos Jul 2, 2024
fb4bb73
update with a event detecting utils
Foivos Jul 3, 2024
c3d65b4
remove scaling to split into two PRs
Foivos Jul 4, 2024
7d0ae47
Merge branch 'feat/testing' into feat/flow-limits
Foivos Jul 4, 2024
4d335fb
resolve all conflicts from merge
Foivos Jul 4, 2024
c339779
made lint happy
Foivos Jul 4, 2024
2fbd038
seperate tests to move and js
Foivos Jul 4, 2024
9d810fe
try to run sui localnet again
Foivos Jul 4, 2024
56623c4
add sui-test-validator to path
Foivos Jul 4, 2024
9ce9418
ls
Foivos Jul 4, 2024
3952378
seperate tests properly
Foivos Jul 4, 2024
ac8e05c
ls
Foivos Jul 4, 2024
cc0037a
ls again
Foivos Jul 4, 2024
2c8225d
skip cache
Foivos Jul 4, 2024
ae2f1b6
use correct sui-test-validator
Foivos Jul 4, 2024
c0c7314
try to run in parralel
Foivos Jul 4, 2024
41e674f
try waiting for localnet
Foivos Jul 4, 2024
2c9d173
Merge remote-tracking branch 'origin/main' into feat/its-scale-coins
Foivos Jul 30, 2024
f7c04a0
fixed move tests
Foivos Jul 30, 2024
3256b02
fix lint
Foivos Jul 30, 2024
88b32a9
fix js tests
Foivos Jul 30, 2024
483a0cf
fix install
Foivos Jul 30, 2024
6097926
prettier
Foivos Jul 30, 2024
b5c9e33
Merge branch 'feat/its-scale-coins' into feat/flow-limits
Foivos Jul 30, 2024
3586feb
fix move tests
Foivos Jul 30, 2024
30ee624
clean move.toml
Foivos Jul 31, 2024
66cbc69
Merge remote-tracking branch 'origin/main' into feat/flow-limits
Foivos Jul 31, 2024
b4ab1d9
fix move tests
Foivos Jul 31, 2024
0693809
add support for HUB routing
Foivos Jul 31, 2024
2626a5b
Merge remote-tracking branch 'origin/main' into feat/its-hub
Foivos Jul 31, 2024
8d7be3f
address some comments
Foivos Aug 1, 2024
ae88251
fix some logic
Foivos Aug 1, 2024
72ca6f1
finished with its service coverage
Foivos Aug 3, 2024
fee6aeb
update logic to match evm
Foivos Aug 26, 2024
22e366a
Merge remote-tracking branch 'origin/main' into feat/its-hub
Foivos Sep 2, 2024
a624045
Merge branch 'feat/its-hub' into feat/its-tests-actual
Foivos Sep 2, 2024
0d8e05e
fix tests
Foivos Sep 2, 2024
4df83fb
Merge remote-tracking branch 'origin/main' into feat/its-tests-actual
Foivos Sep 3, 2024
0355648
fix tests
Foivos Sep 3, 2024
561b5ba
Add some comments
Foivos Sep 3, 2024
aab4502
Addressed comments
Foivos Sep 3, 2024
80fcb3b
remove unused constant
Foivos Sep 3, 2024
21bd212
Update move/its/tests/coin.move
Foivos Sep 4, 2024
3b88a6a
Update move/its/sources/utils.move
Foivos Sep 4, 2024
24a250b
Update move/its/sources/coin_management.move
Foivos Sep 4, 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
34 changes: 23 additions & 11 deletions move/governance/sources/governance/governance.move
Original file line number Diff line number Diff line change
Expand Up @@ -123,37 +123,49 @@ use sui::test_scenario;
#[test_only]
use sui::test_utils;

#[test_only]
public fun new_for_testing(
trusted_source_chain: String,
trusted_source_address: String,
message_type: u256,
ctx: &mut TxContext,
): Governance {
Governance {
id: object::new(ctx),
trusted_source_chain,
trusted_source_address,
message_type,
channel: channel::new(ctx),
caps: table::new<ID, UpgradeCap>(ctx),
}
milapsheth marked this conversation as resolved.
Show resolved Hide resolved
}
#[test]
fun test_new() {
let trusted_source_chain = ascii::string(b"Axelar");
let trusted_source_address = ascii::string(b"0x0");
let message_type = 2;
let mut ctx = tx_context::dummy();
let package_id = object::id_from_bytes(
hex::decode(type_name::get<Governance>().get_address().into_bytes()),
hex::decode(
type_name::get<Governance>().get_address().into_bytes()
)
);
let upgrade_cap = package::test_publish(package_id, &mut ctx);
let initial_owner = @0x1;
let mut scenario = test_scenario::begin(initial_owner);
{
{
test_scenario::sender(&scenario);
new(
trusted_source_chain,
trusted_source_address,
message_type,
upgrade_cap,
&mut ctx,
);
new(trusted_source_chain, trusted_source_address, message_type, upgrade_cap, &mut ctx);
};

test_scenario::next_tx(&mut scenario, initial_owner);
{
{
let governance = test_scenario::take_shared<Governance>(&scenario);
test_scenario::return_shared(governance);
};

test_scenario::end(scenario);
}
}

#[test]
#[expected_failure(abort_code = ENotSelfUpgradeCap)]
Expand Down
23 changes: 23 additions & 0 deletions move/its/sources/address_tracker.move
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ module its::address_tracker {

use sui::table::{Self, Table};

// ------
// Errors
// ------
/// Attempt to borrow a trusted address but it's not registered.
const ENoAddress: u64 = 0;

Expand All @@ -13,6 +16,9 @@ module its::address_tracker {
trusted_addresses: Table<String, String>
}

// ------
// Getters
// ------
/// Get the trusted address for a chain.
public fun get_trusted_address(
self: &InterchainAddressTracker, chain_name: String
Expand Down Expand Up @@ -55,6 +61,7 @@ module its::address_tracker {
}
}

// === Tests ===
#[test]
fun test_address_tracker() {
let ctx = &mut sui::tx_context::dummy();
Expand Down Expand Up @@ -87,6 +94,22 @@ module its::address_tracker {
assert!(self.is_trusted_address(chain2, address1) == true, 10);
assert!(self.is_trusted_address(chain2, address2) == false, 11);

assert!(self.trusted_addresses.contains(chain1), 12);
assert!(self.trusted_addresses.contains(chain2), 13);

self.set_trusted_address(chain1, std::ascii::string(b""));
self.set_trusted_address(chain2, std::ascii::string(b""));

assert!(!self.trusted_addresses.contains(chain1), 14);
assert!(!self.trusted_addresses.contains(chain2), 15);


self.set_trusted_address(chain1, std::ascii::string(b""));
self.set_trusted_address(chain2, std::ascii::string(b""));

assert!(!self.trusted_addresses.contains(chain1), 16);
assert!(!self.trusted_addresses.contains(chain2), 17);

sui::test_utils::destroy(self);
}

Expand Down
24 changes: 24 additions & 0 deletions move/its/sources/coin_info.move
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ module its::coin_info {
&self.metadata
}

// === Tests ===
#[test_only]
public fun drop<T>(coin_info: CoinInfo<T>) {
let CoinInfo {name: _, symbol: _, decimals: _, remote_decimals: _, metadata } = coin_info;
Expand All @@ -77,4 +78,27 @@ module its::coin_info {
metadata.destroy_none()
}
}

#[test]
fun test_from_metadata() {
let ctx = &mut tx_context::dummy();
let metadata = its::coin::create_metadata(b"Symbol", 8, ctx);
let metadata_bytes = sui::bcs::to_bytes(&metadata);

let name = metadata.get_name();
let symbol = metadata.get_symbol();
let decimals = metadata.get_decimals();
let remote_decimals = 31;

let coin_info = from_metadata(metadata, remote_decimals);

assert!(coin_info.name() == name, 0);
assert!(coin_info.symbol() == symbol, 1);
assert!(coin_info.decimals() == decimals, 2);
assert!(coin_info.remote_decimals() == remote_decimals, 3);
assert!(sui::bcs::to_bytes(coin_info.metadata().borrow()) == metadata_bytes, 4);
assert!(coin_info.scaling() == utils::pow(10, remote_decimals - decimals), 5);

sui::test_utils::destroy(coin_info);
}
}
12 changes: 11 additions & 1 deletion move/its/sources/coin_management.move
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ module its::coin_management {

use its::flow_limit::{Self, FlowLimit};

// ------
// Errors
// ------
/// Trying to add a distributor to a `CoinManagement` that does not
/// have a `TreasuryCap`.
const EDistributorNeedsTreasuryCap: u64 = 0;
Expand All @@ -26,6 +29,9 @@ module its::coin_management {
dust: u256,
}

// ------
// Public Functions to create CoinManagement
// ------
/// Create a new `CoinManagement` with a `TreasuryCap`.
/// This type of `CoinManagement` allows minting and burning of coins.
public fun new_with_cap<T>(treasury_cap: TreasuryCap<T>): CoinManagement<T> {
Expand Down Expand Up @@ -54,6 +60,10 @@ module its::coin_management {
}
}


// ------
// Functions that modify CoinManagement
// ------
/// Adds the distributor address to the `CoinManagement`.
/// Only works for a `CoinManagement` with a `TreasuryCap`.
public fun add_distributor<T>(self: &mut CoinManagement<T>, distributor: address) {
Expand Down Expand Up @@ -136,7 +146,7 @@ module its::coin_management {
self.treasury_cap.is_some()
}


// === Tests ===
#[test_only]
public struct COIN_MANAGEMENT has drop {}

Expand Down
15 changes: 8 additions & 7 deletions move/its/sources/discovery.move
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,7 @@ module its::discovery {
)
}

// === Tests ===
#[test_only]
fun get_initial_tx(self: &ITS): Transaction {
let mut arg = vector[0];
Expand Down Expand Up @@ -209,7 +210,7 @@ module its::discovery {
#[test]
fun test_discovery_initial() {
let ctx = &mut sui::tx_context::dummy();
let mut its = its::its::new();
let mut its = its::its::new_for_testing();
let mut discovery = axelar_gateway::discovery::new(ctx);

register_transaction(&mut its, &mut discovery);
Expand All @@ -224,7 +225,7 @@ module its::discovery {
#[test]
fun test_discovery_interchain_transfer() {
let ctx = &mut sui::tx_context::dummy();
let mut its = its::its::new();
let mut its = its::its::new_for_testing();
let mut discovery = axelar_gateway::discovery::new(ctx);

register_transaction(&mut its, &mut discovery);
Expand All @@ -245,7 +246,7 @@ module its::discovery {
let payload = writer.into_bytes();

let type_arg = std::type_name::get<RelayerDiscovery>();
its.test_add_registered_coin_type(its::token_id::from_address(token_id), type_arg);
its.add_registered_coin_type_for_testing(its::token_id::from_address(token_id), type_arg);
let tx_block = get_call_info(&its, payload);

let mut reader = abi::new_reader(payload);
Expand Down Expand Up @@ -277,7 +278,7 @@ module its::discovery {
#[test]
fun test_discovery_interchain_transfer_with_data() {
let ctx = &mut sui::tx_context::dummy();
let mut its = its::its::new();
let mut its = its::its::new_for_testing();
let mut discovery = axelar_gateway::discovery::new(ctx);

register_transaction(&mut its, &mut discovery);
Expand Down Expand Up @@ -305,7 +306,7 @@ module its::discovery {
.write_bytes(data);
let payload = writer.into_bytes();

its.test_add_registered_coin_type(its::token_id::from_address(token_id), std::type_name::get<RelayerDiscovery>());
its.add_registered_coin_type_for_testing(its::token_id::from_address(token_id), std::type_name::get<RelayerDiscovery>());

let mut reader = abi::new_reader(payload);
reader.skip_slot(); // skip message_type
Expand All @@ -319,7 +320,7 @@ module its::discovery {
#[test]
fun test_discovery_deploy_token() {
let ctx = &mut sui::tx_context::dummy();
let mut its = its::its::new();
let mut its = its::its::new_for_testing();
let mut discovery = axelar_gateway::discovery::new(ctx);

register_transaction(&mut its, &mut discovery);
Expand All @@ -340,7 +341,7 @@ module its::discovery {
let payload = writer.into_bytes();

let type_arg = std::type_name::get<RelayerDiscovery>();
its.test_add_unregistered_coin_type(its::token_id::unregistered_token_id(&ascii::string(symbol), (decimals as u8)), type_arg);
its.add_unregistered_coin_type_for_testing(its::token_id::unregistered_token_id(&ascii::string(symbol), (decimals as u8)), type_arg);
let tx_block = get_call_info(&its, payload);

let mut reader = abi::new_reader(payload);
Expand Down
Loading
Loading