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

test(iota-indexer): Add tests for CoinApi #3580

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
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
Loading