Skip to content

Commit

Permalink
test(iota-indexer): Add tests for CoinApi (#3580)
Browse files Browse the repository at this point in the history
* 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
tomxey authored and sergiupopescu199 committed Oct 31, 2024
1 parent b6b1675 commit 0682515
Show file tree
Hide file tree
Showing 6 changed files with 607 additions and 15 deletions.
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"
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)
}
}
Loading

0 comments on commit 0682515

Please sign in to comment.