Skip to content

Commit

Permalink
Merge branch 'spec_update_vesting' of https://github.com/movebit/apto…
Browse files Browse the repository at this point in the history
…s-core into spec_update_vesting
  • Loading branch information
UIZorrot committed Jul 21, 2023
2 parents 22977e3 + a22728d commit cf1cd1f
Show file tree
Hide file tree
Showing 23 changed files with 559 additions and 98 deletions.
2 changes: 1 addition & 1 deletion api/src/tests/objects.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ async fn test_gen_object() {
let user_addr = user.address();

// Publish packages
let named_addresses = vec![("token_objects".to_string(), user_addr)];
let named_addresses = vec![("hero".to_string(), user_addr)];
let txn = futures::executor::block_on(async move {
let path = PathBuf::from(std::env!("CARGO_MANIFEST_DIR"))
.join("../aptos-move/move-examples/token_objects/hero");
Expand Down
2 changes: 1 addition & 1 deletion aptos-move/e2e-move-tests/src/tests/token_objects.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ fn test_basic_token() {
let mut build_options = aptos_framework::BuildOptions::default();
build_options
.named_addresses
.insert("token_objects".to_string(), addr);
.insert("hero".to_string(), addr);

let result = h.publish_package_with_options(
&account,
Expand Down
2 changes: 1 addition & 1 deletion aptos-move/framework/aptos-framework/doc/event.md
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ Destroy a unique handle.

<pre><code><b>pragma</b> opaque;
<b>aborts_if</b> [abstract] <b>false</b>;
<b>ensures</b> handle_ref.<a href="event.md#0x1_event_counter">counter</a> &lt; MAX_U64 ==&gt; handle_ref.counter == <b>old</b>(handle_ref.counter) + 1;
<b>ensures</b> [concrete] handle_ref.counter == <b>old</b>(handle_ref.counter) + 1;
</code></pre>


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ spec aptos_framework::event {
spec emit_event {
pragma opaque;
aborts_if [abstract] false;
ensures handle_ref.counter < MAX_U64 ==> handle_ref.counter == old(handle_ref.counter) + 1;
ensures [concrete] handle_ref.counter == old(handle_ref.counter) + 1;
}

/// Native function use opaque.
Expand Down
2 changes: 1 addition & 1 deletion aptos-move/move-examples/swap/Move.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[package]
name = "CoinWrapper"
name = "swap"
version = "0.0.0"

[addresses]
Expand Down
29 changes: 22 additions & 7 deletions aptos-move/move-examples/tests/move_unit_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -194,13 +194,28 @@ fn test_shared_account() {

#[test]
fn test_token_objects() {
let named_address = BTreeMap::from([(
String::from("token_objects"),
AccountAddress::from_hex_literal("0xcafe").unwrap(),
)]);
run_tests_for_pkg("token_objects/hero", named_address.clone());
run_tests_for_pkg("token_objects/token_lockup", named_address.clone());
run_tests_for_pkg("token_objects/ambassador/move", named_address);
let named_addresses = BTreeMap::from([
(
String::from("ambassador"),
AccountAddress::from_hex_literal("0xcafe").unwrap(),
),
(
String::from("hero"),
AccountAddress::from_hex_literal("0xcafe").unwrap(),
),
(
String::from("knight"),
AccountAddress::from_hex_literal("0xcafe").unwrap(),
),
(
String::from("token_lockup"),
AccountAddress::from_hex_literal("0xcafe").unwrap(),
),
]);
run_tests_for_pkg("token_objects/ambassador", named_addresses.clone());
run_tests_for_pkg("token_objects/hero", named_addresses.clone());
run_tests_for_pkg("token_objects/knight", named_addresses.clone());
run_tests_for_pkg("token_objects/token_lockup", named_addresses);
}

#[test]
Expand Down
4 changes: 2 additions & 2 deletions aptos-move/move-examples/token_objects/ambassador/Move.toml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
[package]
name = 'ambassador_token'
name = 'ambassador'
version = '1.0.0'

[addresses]
token_objects = "0xCAFE"
ambassador = "_"

[dependencies]
AptosFramework = { local = "../../../framework/aptos-framework" }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
/// The rank is stored in the property map, thus displayed in a wallet as a trait of the token.
/// The token uri is the concatenation of the base uri and the rank, where the base uri is given
/// as an argument of the minting function. So, the token uri changes when the rank changes.
module token_objects::ambassador {
module ambassador::ambassador {
use std::error;
use std::option;
use std::string::{Self, String};
Expand Down
4 changes: 2 additions & 2 deletions aptos-move/move-examples/token_objects/hero/Move.toml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
[package]
name = "TokenObjects"
name = "Hero"
version = "0.0.0"

[addresses]
token_objects = "_"
hero = "_"

[dependencies]
AptosFramework = { local = "../../../framework/aptos-framework" }
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module token_objects::hero {
module hero::hero {
use std::error;
use std::option::{Self, Option};
use std::signer;
Expand Down
2 changes: 1 addition & 1 deletion aptos-move/move-examples/token_objects/knight/Move.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name = 'knight'
version = '1.0.0'

[addresses]
token_objects = "_"
knight = "_"

[dependencies]
AptosFramework = { local = "../../../framework/aptos-framework" }
Expand Down
22 changes: 11 additions & 11 deletions aptos-move/move-examples/token_objects/knight/sources/food.move
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
/// This module implements the the food tokens (fungible token). When the module initializes,
/// it creates the collection and two fungible tokens such as Corn and Meat.
module token_objects::food {
use std::error;
use std::option;
use std::signer;
use std::string::{Self, String};
module knight::food {
use aptos_framework::fungible_asset::{Self, Metadata};
use aptos_framework::object::{Self, Object};
use aptos_framework::primary_fungible_store;
use aptos_token_objects::collection;
use aptos_token_objects::property_map;
use aptos_token_objects::token;
use std::error;
use std::option;
use std::signer;
use std::string::{Self, String};

friend knight::knight;

/// The token does not exist
const ETOKEN_DOES_NOT_EXIST: u64 = 1;
Expand Down Expand Up @@ -53,8 +55,6 @@ module token_objects::food {
const CONDITION_HUNGRY: vector<u8> = b"Hungry";
const CONDITION_GOOD: vector<u8> = b"Good";

friend token_objects::knight;

#[resource_group_member(group = aptos_framework::object::ObjectGroup)]
// Food Token
struct FoodToken has key {
Expand Down Expand Up @@ -131,7 +131,7 @@ module token_objects::food {
#[view]
/// Returns the food token address by name
public fun food_token_address(food_token_name: String): address {
token::create_token_address(&@token_objects, &string::utf8(FOOD_COLLECTION_NAME), &food_token_name)
token::create_token_address(&@knight, &string::utf8(FOOD_COLLECTION_NAME), &food_token_name)
}

/// Mints the given amount of the corn token to the given receiver.
Expand Down Expand Up @@ -277,10 +277,10 @@ module token_objects::food {
init_module(creator);
}

#[test(creator = @token_objects, user1 = @0x456, user2 = @0x789)]
#[test(creator = @knight, user1 = @0x456, user2 = @0x789)]
public fun test_food(creator: &signer, user1: &signer, user2: &signer) acquires FoodToken {
// This test assumes that the creator's address is equal to @token_objects.
assert!(signer::address_of(creator) == @token_objects, 0);
// This test assumes that the creator's address is equal to @knight.
assert!(signer::address_of(creator) == @knight, 0);

// ---------------------------------------------------------------------
// Creator creates the collection, and mints corn and meat tokens in it.
Expand Down
26 changes: 13 additions & 13 deletions aptos-move/move-examples/token_objects/knight/sources/knight.move
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
/// This module implements the knight token (non-fungible token) including the
/// functions create the collection and the knight tokens, and the function to feed a
/// knight token with food tokens to increase the knight's health point.
module token_objects::knight {
use std::option;
use std::string::{Self, String};
module knight::knight {
use aptos_framework::event;
use aptos_framework::object::{Self, Object};
use aptos_token_objects::collection;
use aptos_token_objects::property_map;
use aptos_token_objects::token;
use token_objects::food::{Self, FoodToken};
use std::option;
use std::signer;
use std::string::{Self, String};
use knight::food::{Self, FoodToken};

/// The token does not exist
const ETOKEN_DOES_NOT_EXIST: u64 = 1;
Expand Down Expand Up @@ -80,7 +81,7 @@ module token_objects::knight {
#[view]
/// Returns the knight token address by name
public fun knight_token_address(knight_token_name: String): address {
token::create_token_address(&@token_objects, &string::utf8(KNIGHT_COLLECTION_NAME), &knight_token_name)
token::create_token_address(&@knight, &string::utf8(KNIGHT_COLLECTION_NAME), &knight_token_name)
}

/// Mints an knight token. This function mints a new knight token and transfers it to the
Expand Down Expand Up @@ -115,8 +116,10 @@ module token_objects::knight {
let property_mutator_ref = property_map::generate_mutator_ref(&constructor_ref);

// Transfers the token to the `soul_bound_to` address
let linear_transfer_ref = object::generate_linear_transfer_ref(&transfer_ref);
object::transfer_with_ref(linear_transfer_ref, receiver);
if (receiver != signer::address_of(creator)) {
let linear_transfer_ref = object::generate_linear_transfer_ref(&transfer_ref);
object::transfer_with_ref(linear_transfer_ref, receiver);
};

// Initializes the knight health point as 0
move_to(&object_signer, HealthPoint { value: 1 });
Expand Down Expand Up @@ -215,13 +218,10 @@ module token_objects::knight {
);
}

#[test_only]
use std::signer;

#[test(creator = @token_objects, user1 = @0x456)]
#[test(creator = @knight, user1 = @0x456)]
public fun test_knight(creator: &signer, user1: &signer) acquires HealthPoint, KnightToken {
// This test assumes that the creator's address is equal to @token_objects.
assert!(signer::address_of(creator) == @token_objects, 0);
// This test assumes that the creator's address is equal to @knight.
assert!(signer::address_of(creator) == @knight, 0);

// ---------------------------------------------------------------------
// Creator creates the collection, and mints corn and meat tokens in it.
Expand Down
4 changes: 2 additions & 2 deletions aptos-move/move-examples/token_objects/token_lockup/Move.toml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
[package]
name = 'Token Lockup'
name = 'token_lockup'
version = '1.0.0'

[addresses]
token_objects = "_"
token_lockup = "_"

[dependencies]
AptosFramework = { local = "../../../framework/aptos-framework" }
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module token_objects::token_lockup {
module token_lockup::token_lockup {
use std::signer;
use std::option;
use std::error;
Expand Down
Loading

0 comments on commit cf1cd1f

Please sign in to comment.