-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test(iota-indexer): Add tests for
CoinApi
(#3580)
* feat(iota-indexer): Add tests for CoinApi * Simplify `once_prepare_addr_with_iota_and_custom_coins`, reorder modules in main.rs * Fixes after rebase * Change return type of `once_prepare_addr_with_iota_and_custom_coins` * Rename helper test functions * Fix clippy * Fix clippy
- Loading branch information
1 parent
b6b1675
commit 0682515
Showing
6 changed files
with
607 additions
and
15 deletions.
There are no files selected for viewing
9 changes: 9 additions & 0 deletions
9
crates/iota-indexer/tests/data/dummy_modules_publish/Move.toml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
[package] | ||
name = "Examples" | ||
version = "0.0.1" | ||
|
||
[dependencies] | ||
Iota = { local = "../../../../iota-framework/packages/iota-framework" } | ||
|
||
[addresses] | ||
examples = "0x0" |
40 changes: 40 additions & 0 deletions
40
crates/iota-indexer/tests/data/dummy_modules_publish/sources/trusted_coin.move
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
// Copyright (c) Mysten Labs, Inc. | ||
// Modifications Copyright (c) 2024 IOTA Stiftung | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
/// Example coin with a trusted owner responsible for minting/burning (e.g., a stablecoin) | ||
module examples::trusted_coin { | ||
use std::option; | ||
use iota::coin::{Self, TreasuryCap}; | ||
use iota::transfer; | ||
use iota::tx_context::{Self, TxContext}; | ||
|
||
/// Name of the coin | ||
struct TRUSTED_COIN has drop {} | ||
|
||
/// Register the trusted currency to acquire its `TreasuryCap`. Because | ||
/// this is a module initializer, it ensures the currency only gets | ||
/// registered once. | ||
fun init(witness: TRUSTED_COIN, ctx: &mut TxContext) { | ||
// Get a treasury cap for the coin and give it to the transaction | ||
// sender | ||
let (treasury_cap, metadata) = coin::create_currency<TRUSTED_COIN>(witness, 2, b"TRUSTED", b"Trusted Coin", b"Trusted Coin for test", option::none(), ctx); | ||
transfer::public_freeze_object(metadata); | ||
transfer::public_transfer(treasury_cap, tx_context::sender(ctx)) | ||
} | ||
|
||
public entry fun mint(treasury_cap: &mut TreasuryCap<TRUSTED_COIN>, amount: u64, ctx: &mut TxContext) { | ||
let coin = coin::mint<TRUSTED_COIN>(treasury_cap, amount, ctx); | ||
transfer::public_transfer(coin, tx_context::sender(ctx)); | ||
} | ||
|
||
public entry fun transfer(treasury_cap: TreasuryCap<TRUSTED_COIN>, recipient: address) { | ||
transfer::public_transfer(treasury_cap, recipient); | ||
} | ||
|
||
#[test_only] | ||
/// Wrapper of module initializer for testing | ||
public fun test_init(ctx: &mut TxContext) { | ||
init(TRUSTED_COIN {}, ctx) | ||
} | ||
} |
Oops, something went wrong.