Skip to content

Commit

Permalink
Cleanup after introduction of entry modifier (MystenLabs#2522)
Browse files Browse the repository at this point in the history
* Cleanup after introduction of entry modifier

- Removed redundant 'entry' functions
- Removed 'public entry' from tests and test_only functions
- Fixed docs
  • Loading branch information
tnowacki authored Jun 14, 2022
1 parent b027b24 commit 2a0df25
Show file tree
Hide file tree
Showing 41 changed files with 172 additions and 177 deletions.
21 changes: 16 additions & 5 deletions crates/sui-adapter-transactional-tests/tests/sui/coin_transfer.exp
Original file line number Diff line number Diff line change
@@ -1,20 +1,31 @@
processed 5 tasks
processed 8 tasks

init:
A: object(100), B: object(101)
A: object(100), B: object(101), C: object(102)

task 1 'view-object'. lines 8-8:
Owner: Account Address ( A )
Contents: Sui::Coin::Coin<Sui::SUI::SUI> {id: Sui::ID::VersionedID {id: Sui::ID::UniqueID {id: Sui::ID::ID {bytes: fake(100)}}, version: 0u64}, balance: Sui::Balance::Balance<Sui::SUI::SUI> {value: 100000u64}}

task 2 'run'. lines 10-10:
created: object(105)
written: object(100), object(104)
created: object(106)
written: object(100), object(105)

task 3 'view-object'. lines 12-12:
Owner: Account Address ( A )
Contents: Sui::Coin::Coin<Sui::SUI::SUI> {id: Sui::ID::VersionedID {id: Sui::ID::UniqueID {id: Sui::ID::ID {bytes: fake(100)}}, version: 1u64}, balance: Sui::Balance::Balance<Sui::SUI::SUI> {value: 99990u64}}

task 4 'view-object'. lines 14-14:
Owner: Account Address ( B )
Contents: Sui::Coin::Coin<Sui::SUI::SUI> {id: Sui::ID::VersionedID {id: Sui::ID::UniqueID {id: Sui::ID::ID {bytes: fake(105)}}, version: 1u64}, balance: Sui::Balance::Balance<Sui::SUI::SUI> {value: 10u64}}
Contents: Sui::Coin::Coin<Sui::SUI::SUI> {id: Sui::ID::VersionedID {id: Sui::ID::UniqueID {id: Sui::ID::ID {bytes: fake(106)}}, version: 1u64}, balance: Sui::Balance::Balance<Sui::SUI::SUI> {value: 10u64}}

task 5 'run'. lines 16-16:
written: object(100), object(107)

task 6 'view-object'. lines 18-18:
Owner: Account Address ( C )
Contents: Sui::Coin::Coin<Sui::SUI::SUI> {id: Sui::ID::VersionedID {id: Sui::ID::UniqueID {id: Sui::ID::ID {bytes: fake(100)}}, version: 2u64}, balance: Sui::Balance::Balance<Sui::SUI::SUI> {value: 99990u64}}

task 7 'view-object'. lines 20-20:
Owner: Account Address ( B )
Contents: Sui::Coin::Coin<Sui::SUI::SUI> {id: Sui::ID::VersionedID {id: Sui::ID::UniqueID {id: Sui::ID::ID {bytes: fake(107)}}, version: 1u64}, balance: Sui::Balance::Balance<Sui::SUI::SUI> {value: 99600u64}}
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,18 @@

// Test basic coin transfer

//# init --accounts A B
//# init --accounts A B C

//# view-object 100

//# run Sui::Coin::transfer_ --type-args Sui::SUI::SUI --args object(100) 10 @B
//# run Sui::Coin::split_and_transfer --type-args Sui::SUI::SUI --args object(100) 10 @B --sender A

//# view-object 100

//# view-object 105
//# view-object 106

//# run Sui::Coin::transfer --type-args Sui::SUI::SUI --args object(100) @C --sender B

//# view-object 100

//# view-object 107
7 changes: 1 addition & 6 deletions crates/sui-framework/sources/Bag.move
Original file line number Diff line number Diff line change
Expand Up @@ -124,12 +124,7 @@ module Sui::Bag {
}

/// Transfer the entire Bag to `recipient`.
public entry fun transfer_(c: Bag, recipient: address) {
Transfer::transfer(c, recipient)
}

/// Transfer the entire Bag to `recipient`.
public fun transfer(c: Bag, recipient: address) {
public entry fun transfer(c: Bag, recipient: address) {
Transfer::transfer(c, recipient)
}

Expand Down
19 changes: 4 additions & 15 deletions crates/sui-framework/sources/Coin.move
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ module Sui::Coin {
// === Functionality for Coin<T> holders ===

/// Send `c` to `recipient`
public fun transfer<T>(c: Coin<T>, recipient: address) {
public entry fun transfer<T>(c: Coin<T>, recipient: address) {
Transfer::transfer(c, recipient)
}

Expand All @@ -76,14 +76,14 @@ module Sui::Coin {

/// Consume the coin `c` and add its value to `self`.
/// Aborts if `c.value + self.value > U64_MAX`
public fun join<T>(self: &mut Coin<T>, c: Coin<T>) {
public entry fun join<T>(self: &mut Coin<T>, c: Coin<T>) {
let Coin { id, balance } = c;
ID::delete(id);
Balance::join(&mut self.balance, balance);
}

/// Join everything in `coins` with `self`
public fun join_vec<T>(self: &mut Coin<T>, coins: vector<Coin<T>>) {
public entry fun join_vec<T>(self: &mut Coin<T>, coins: vector<Coin<T>>) {
let i = 0;
let len = vector::length(&coins);
while (i < len) {
Expand Down Expand Up @@ -172,21 +172,10 @@ module Sui::Coin {

/// Send `amount` units of `c` to `recipient
/// Aborts with `EVALUE` if `amount` is greater than or equal to `amount`
public entry fun transfer_<T>(c: &mut Coin<T>, amount: u64, recipient: address, ctx: &mut TxContext) {
public entry fun split_and_transfer<T>(c: &mut Coin<T>, amount: u64, recipient: address, ctx: &mut TxContext) {
Transfer::transfer(withdraw(&mut c.balance, amount, ctx), recipient)
}

/// Consume the coin `c` and add its value to `self`.
/// Aborts if `c.value + self.value > U64_MAX`
public entry fun join_<T>(self: &mut Coin<T>, c: Coin<T>) {
join(self, c)
}

/// Join everything in `coins` with `self`
public entry fun join_vec_<T>(self: &mut Coin<T>, coins: vector<Coin<T>>) {
join_vec(self, coins)
}

/// Split coin `self` to two coins, one with balance `split_amount`,
/// and the remaining balance is left is `self`.
public entry fun split<T>(self: &mut Coin<T>, split_amount: u64, ctx: &mut TxContext) {
Expand Down
7 changes: 1 addition & 6 deletions crates/sui-framework/sources/Collection.move
Original file line number Diff line number Diff line change
Expand Up @@ -146,12 +146,7 @@ module Sui::Collection {
}

/// Transfer the entire collection to `recipient`.
public entry fun transfer_<T: key + store>(c: Collection<T>, recipient: address) {
Transfer::transfer(c, recipient)
}

/// Transfer the entire collection to `recipient`.
public fun transfer<T: key + store>(c: Collection<T>, recipient: address) {
public entry fun transfer<T: key + store>(c: Collection<T>, recipient: address) {
Transfer::transfer(c, recipient)
}

Expand Down
2 changes: 1 addition & 1 deletion crates/sui-framework/sources/DevNetNFT.move
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ module Sui::DevNetNFTTests {
use Sui::UTF8;

#[test]
public entry fun mint_transfer_update() {
fun mint_transfer_update() {
let addr1 = @0xA;
let addr2 = @0xB;
// create the NFT
Expand Down
2 changes: 1 addition & 1 deletion crates/sui-framework/sources/Governance/ValidatorSet.move
Original file line number Diff line number Diff line change
Expand Up @@ -408,7 +408,7 @@ module Sui::ValidatorSet {
}

#[test_only]
public entry fun destroy_for_testing(
public fun destroy_for_testing(
self: ValidatorSet,
ctx: &mut TxContext
) {
Expand Down
14 changes: 7 additions & 7 deletions crates/sui-framework/tests/BagTests.move
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ module Sui::BagTests {
}

#[test]
public entry fun test_bag() {
fun test_bag() {
let sender = @0x0;
let scenario = &mut TestScenario::begin(&sender);

Expand Down Expand Up @@ -55,32 +55,32 @@ module Sui::BagTests {

#[test]
#[expected_failure(abort_code = 520)]
public entry fun test_init_with_invalid_max_capacity() {
fun test_init_with_invalid_max_capacity() {
let ctx = TxContext::dummy();
// Sui::Bag::DEFAULT_MAX_CAPACITY is not readable outside the module
let max_capacity = 65536;
let bag = Bag::new_with_max_capacity(&mut ctx, max_capacity + 1);
Bag::transfer_(bag, TxContext::sender(&ctx));
Bag::transfer(bag, TxContext::sender(&ctx));
}

#[test]
#[expected_failure(abort_code = 520)]
public entry fun test_init_with_zero() {
fun test_init_with_zero() {
let ctx = TxContext::dummy();
let bag = Bag::new_with_max_capacity(&mut ctx, 0);
Bag::transfer_(bag, TxContext::sender(&ctx));
Bag::transfer(bag, TxContext::sender(&ctx));
}

#[test]
#[expected_failure(abort_code = 776)]
public entry fun test_exceed_max_capacity() {
fun test_exceed_max_capacity() {
let ctx = TxContext::dummy();
let bag = Bag::new_with_max_capacity(&mut ctx, 1);

let obj1 = Object1 { id: TxContext::new_id(&mut ctx) };
Bag::add(&mut bag, obj1);
let obj2 = Object2 { id: TxContext::new_id(&mut ctx) };
Bag::add(&mut bag, obj2);
Bag::transfer_(bag, TxContext::sender(&ctx));
Bag::transfer(bag, TxContext::sender(&ctx));
}
}
16 changes: 8 additions & 8 deletions crates/sui-framework/tests/CollectionTests.move
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ module Sui::CollectionTests {
}

#[test]
public entry fun test_collection() {
fun test_collection() {
let sender = @0x0;
let scenario = &mut TestScenario::begin(&sender);

Expand Down Expand Up @@ -47,7 +47,7 @@ module Sui::CollectionTests {
}

#[test]
public entry fun test_collection_bag_interaction() {
fun test_collection_bag_interaction() {
let sender = @0x0;
let scenario = &mut TestScenario::begin(&sender);

Expand Down Expand Up @@ -109,32 +109,32 @@ module Sui::CollectionTests {

#[test]
#[expected_failure(abort_code = 520)]
public entry fun test_init_with_invalid_max_capacity() {
fun test_init_with_invalid_max_capacity() {
let ctx = TxContext::dummy();
// Sui::Collection::DEFAULT_MAX_CAPACITY is not readable outside the module
let max_capacity = 65536;
let collection = Collection::new_with_max_capacity<Object>(&mut ctx, max_capacity + 1);
Collection::transfer_(collection, TxContext::sender(&ctx));
Collection::transfer(collection, TxContext::sender(&ctx));
}

#[test]
#[expected_failure(abort_code = 520)]
public entry fun test_init_with_zero() {
fun test_init_with_zero() {
let ctx = TxContext::dummy();
let collection = Collection::new_with_max_capacity<Object>(&mut ctx, 0);
Collection::transfer_(collection, TxContext::sender(&ctx));
Collection::transfer(collection, TxContext::sender(&ctx));
}

#[test]
#[expected_failure(abort_code = 776)]
public entry fun test_exceed_max_capacity() {
fun test_exceed_max_capacity() {
let ctx = TxContext::dummy();
let collection = Collection::new_with_max_capacity<Object>(&mut ctx, 1);

let obj1 = Object { id: TxContext::new_id(&mut ctx) };
Collection::add(&mut collection, obj1);
let obj2 = Object { id: TxContext::new_id(&mut ctx) };
Collection::add(&mut collection, obj2);
Collection::transfer_(collection, TxContext::sender(&ctx));
Collection::transfer(collection, TxContext::sender(&ctx));
}
}
2 changes: 1 addition & 1 deletion crates/sui-framework/tests/ValidatorSetTests.move
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ module Sui::ValidatorSetTests {
use Sui::ValidatorSet;

#[test]
public entry fun test_validator_set_flow() {
fun test_validator_set_flow() {
// Create 4 validators, with stake 100, 200, 300, 400.
let (ctx1, validator1) = create_validator(@0x1, 1);
let (_ctx2, validator2) = create_validator(@0x2, 2);
Expand Down
4 changes: 2 additions & 2 deletions crates/sui-framework/tests/ValidatorTests.move
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ module Sui::ValidatorTests {
use Sui::Validator;

#[test]
public entry fun test_validator_owner_flow() {
fun test_validator_owner_flow() {
let sender = @0x1;
let scenario = &mut TestScenario::begin(&sender);
{
Expand Down Expand Up @@ -39,7 +39,7 @@ module Sui::ValidatorTests {
}

#[test]
public entry fun test_pending_validator_flow() {
fun test_pending_validator_flow() {
let sender = @0x1;
let scenario = &mut TestScenario::begin(&sender);
let ctx = TestScenario::ctx(scenario);
Expand Down
2 changes: 1 addition & 1 deletion crates/sui-types/src/coin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ use schemars::JsonSchema;

pub const COIN_MODULE_NAME: &IdentStr = ident_str!("Coin");
pub const COIN_STRUCT_NAME: &IdentStr = COIN_MODULE_NAME;
pub const COIN_JOIN_FUNC_NAME: &IdentStr = ident_str!("join_");
pub const COIN_JOIN_FUNC_NAME: &IdentStr = ident_str!("join");
pub const COIN_SPLIT_VEC_FUNC_NAME: &IdentStr = ident_str!("split_vec");

// Rust version of the Move Sui::Coin::Coin type
Expand Down
24 changes: 12 additions & 12 deletions doc/src/build/json-rpc.md
Original file line number Diff line number Diff line change
Expand Up @@ -125,13 +125,13 @@ actual object ID, for example one obtained from [`sui_getOwnedObjects`](#sui_get
```shell
curl --location --request POST $SUI_RPC_HOST \
--header 'Content-Type: application/json' \
--data-raw '{ "jsonrpc":"2.0",
"method":"sui_transferCoin",
--data-raw '{ "jsonrpc":"2.0",
"method":"sui_transferCoin",
"params":["{{owner_address}}",
"{{coin_object_id}}",
"{{gas_object_id}}",
{{gas_budget}},
"{{to_address}}"],
"{{to_address}}"],
"id":1}' | json_pp
```
A transaction data response will be returned from the gateway server.
Expand Down Expand Up @@ -162,12 +162,12 @@ You will see output resembling:
```shell
curl --location --request POST $SUI_RPC_HOST \
--header 'Content-Type: application/json' \
--data-raw '{ "jsonrpc":"2.0",
"method":"sui_executeTransaction",
--data-raw '{ "jsonrpc":"2.0",
"method":"sui_executeTransaction",
"params":[{
"tx_bytes" : "{{tx_bytes}}",
"signature" : "{{signature}}",
"pub_key" : "{{pub_key}}"}],
"pub_key" : "{{pub_key}}"}],
"id":1}' | json_pp
```

Expand Down Expand Up @@ -203,9 +203,9 @@ curl --location --request POST $SUI_RPC_HOST \
"{{owner_address}}",
"0x2",
"Coin",
"transfer_",
"transfer",
["0x2::SUI::SUI"],
["{{coin_object_id}}",10000, "{{recipient_address}}"],
["{{coin_object_id}}", "{{recipient_address}}"],
"{{gas_object_id}}",
2000
],
Expand All @@ -223,7 +223,7 @@ signature. Gas usage is capped by the gas_budget. The `transfer`
function is described in more detail in
the [Sui Wallet](wallet.md#calling-move-code) documentation.

Calling the `transfer_` function in the `Coin` module serves the same
Calling the `transfer` function in the `Coin` module serves the same
purpose as the native coin transfer ([`sui_transferCoin`](#sui_transfercoin)), and is mostly used for illustration
purposes as native transfer is more efficient when it's applicable
(i.e., we are transferring coins rather than non-coin
Expand All @@ -241,12 +241,12 @@ Publish Move module.
```shell
curl --location --request POST $SUI_RPC_HOST \
--header 'Content-Type: application/json' \
--data-raw '{ "jsonrpc":"2.0",
"method":"sui_publish",
--data-raw '{ "jsonrpc":"2.0",
"method":"sui_publish",
"params":[ "{{owner_address}}",
{{vector_of_compiled_modules}},
"{{gas_object_id}}",
10000],
10000],
"id":1}' | json_pp
```

Expand Down
Loading

0 comments on commit 2a0df25

Please sign in to comment.