Skip to content

Commit

Permalink
change GAS to SUI in the framework (MystenLabs#1062)
Browse files Browse the repository at this point in the history
  • Loading branch information
damirka authored Mar 29, 2022
1 parent d03929e commit 44b5702
Show file tree
Hide file tree
Showing 13 changed files with 53 additions and 52 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ jobs:
uses: actions-rs/cargo@v1
with:
command: clippy
args: --all --tests -- -D clippy::all -D warnings -D clippy::disallowed_method
args: --all --tests -- -D clippy::all -D warnings -D clippy::disallowed_methods

rustfmt:
name: rustfmt
Expand Down
1 change: 1 addition & 0 deletions sui/src/rest_server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ use std::str::FromStr;
use std::sync::{Arc, RwLock};

use dropshot::{endpoint, Query, TypedBody, CONTENT_TYPE_JSON};
#[allow(unused_imports)]
use dropshot::{
ApiDescription, ConfigDropshot, ConfigLogging, ConfigLoggingLevel, HttpError,
HttpResponseUpdatedNoContent, HttpServerStarter, RequestContext,
Expand Down
2 changes: 1 addition & 1 deletion sui/src/unit_tests/cli_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -810,7 +810,7 @@ async fn test_move_call_args_linter_command() -> Result<(), anyhow::Error> {
assert!(resp.is_err());

let err_string = format!("{} ", resp.err().unwrap());
assert!(err_string.contains("Expected argument of type 0x2::ObjectBasics::Object, but found type 0x2::Coin::Coin<0x2::GAS::GAS>"));
assert!(err_string.contains("Expected argument of type 0x2::ObjectBasics::Object, but found type 0x2::Coin::Coin<0x2::SUI::SUI>"));

// Try a proper transfer
let obj_str = format!("0x{:02x}", created_obj);
Expand Down
6 changes: 3 additions & 3 deletions sui_programmability/examples/basics/sources/Sandwich.move
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
module Basics::Sandwich {
use Sui::Coin::{Self, Coin};
use Sui::ID::{Self, VersionedID};
use Sui::GAS::GAS;
use Sui::SUI::SUI;
use Sui::Transfer;
use Sui::TxContext::{Self, TxContext};

Expand All @@ -33,14 +33,14 @@ module Basics::Sandwich {
const EINSUFFICIENT_FUNDS: u64 = 0;

/// Exchange `c` for some ham
public fun buy_ham(c: Coin<GAS>, ctx: &mut TxContext): Ham {
public fun buy_ham(c: Coin<SUI>, ctx: &mut TxContext): Ham {
assert!(Coin::value(&c) == HAM_PRICE, EINSUFFICIENT_FUNDS);
Transfer::transfer(c, GROCERY);
Ham { id: TxContext::new_id(ctx) }
}

/// Exchange `c` for some bread
public fun buy_bread(c: Coin<GAS>, ctx: &mut TxContext): Bread {
public fun buy_bread(c: Coin<SUI>, ctx: &mut TxContext): Bread {
assert!(Coin::value(&c) == BREAD_PRICE, EINSUFFICIENT_FUNDS);
Transfer::transfer(c, GROCERY);
Bread { id: TxContext::new_id(ctx) }
Expand Down
10 changes: 5 additions & 5 deletions sui_programmability/examples/defi/tests/FlashLenderTests.move
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
module DeFi::FlashLenderTests {
use DeFi::FlashLender::{Self, AdminCap, FlashLender};
use Sui::Coin;
use Sui::GAS::GAS;
use Sui::SUI::SUI;
use Sui::TestScenario;

#[test]
Expand All @@ -17,19 +17,19 @@ module DeFi::FlashLenderTests {
let scenario = &mut TestScenario::begin(&admin);
{
let ctx = TestScenario::ctx(scenario);
let coin = Coin::mint_for_testing<GAS>(100, ctx);
let coin = Coin::mint_for_testing<SUI>(100, ctx);
FlashLender::create(coin, 1, ctx);
};
// borrower requests and repays a loan of 10 coins + the fee
TestScenario::next_tx(scenario, &borrower);
{
let lender = TestScenario::remove_object<FlashLender<GAS>>(scenario);
let lender = TestScenario::remove_object<FlashLender<SUI>>(scenario);
let ctx = TestScenario::ctx(scenario);

let (loan, receipt) = FlashLender::loan(&mut lender, 10, ctx);
// in practice, borrower does something (e.g., arbitrage) to make a profit from the loan.
// simulate this by min ting the borrower 5 coins.
let profit = Coin::mint_for_testing<GAS>(5, ctx);
let profit = Coin::mint_for_testing<SUI>(5, ctx);
Coin::join(&mut profit, loan);
let to_keep = Coin::withdraw(&mut profit, 4, ctx);
Coin::keep(to_keep, ctx);
Expand All @@ -40,7 +40,7 @@ module DeFi::FlashLenderTests {
// admin withdraws the 1 coin profit from lending
TestScenario::next_tx(scenario, &admin);
{
let lender = TestScenario::remove_object<FlashLender<GAS>>(scenario);
let lender = TestScenario::remove_object<FlashLender<SUI>>(scenario);
let admin_cap = TestScenario::remove_object<AdminCap>(scenario);
let ctx = TestScenario::ctx(scenario);

Expand Down
6 changes: 3 additions & 3 deletions sui_programmability/examples/nfts/sources/Auction.move
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
/// auction
module NFTs::Auction {
use Sui::Coin::Coin;
use Sui::GAS::GAS;
use Sui::SUI::SUI;
use Sui::ID::{Self, ID, VersionedID};
use Sui::Transfer;
use Sui::TxContext::{Self,TxContext};
Expand All @@ -55,7 +55,7 @@ module NFTs::Auction {
/// ID of the Auction object this bid is intended for
auction_id: ID,
/// Coin used for bidding.
coin: Coin<GAS>
coin: Coin<SUI>
}

// Entry functions.
Expand All @@ -72,7 +72,7 @@ module NFTs::Auction {

/// Creates a bid a and send it to the auctioneer along with the
/// ID of the auction. This is executed by a bidder.
public fun bid(coin: Coin<GAS>, auction_id: ID, auctioneer: address, ctx: &mut TxContext) {
public fun bid(coin: Coin<SUI>, auction_id: ID, auctioneer: address, ctx: &mut TxContext) {
let bid = Bid {
id: TxContext::new_id(ctx),
bidder: TxContext::sender(ctx),
Expand Down
6 changes: 3 additions & 3 deletions sui_programmability/examples/nfts/sources/AuctionLib.move
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ module NFTs::AuctionLib {
use Std::Option::{Self, Option};

use Sui::Coin::{Self, Coin};
use Sui::GAS::GAS;
use Sui::SUI::SUI;
use Sui::ID::{Self, ID, VersionedID};
use Sui::Transfer;
use Sui::TxContext::{Self,TxContext};
Expand All @@ -20,7 +20,7 @@ module NFTs::AuctionLib {
/// Stores information about an auction bid.
struct BidData has store {
/// Coin representing the current (highest) bid.
funds: Coin<GAS>,
funds: Coin<SUI>,
/// Address of the highest bidder.
highest_bidder: address,
}
Expand Down Expand Up @@ -64,7 +64,7 @@ module NFTs::AuctionLib {
/// Updates the auction based on the information in the bid
/// (update auction if higher bid received and send coin back for
/// bids that are too low).
public fun update_auction<T: key + store>(auction: &mut Auction<T>, bidder: address, coin: Coin<GAS>) {
public fun update_auction<T: key + store>(auction: &mut Auction<T>, bidder: address, coin: Coin<SUI>) {
if (Option::is_none(&auction.bid_data)) {
// first bid
let bid_data = BidData {
Expand Down
38 changes: 19 additions & 19 deletions sui_programmability/examples/nfts/sources/Marketplace.move
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ module NFTs::MarketplaceTests {
use Sui::Transfer;
use Sui::NFT::{Self, NFT};
use Sui::Coin::{Self, Coin};
use Sui::GAS::GAS;
use Sui::SUI::SUI;
use Sui::TestScenario::{Self, Scenario};
use NFTs::Marketplace::{Self, Marketplace, Listing};

Expand All @@ -179,10 +179,10 @@ module NFTs::MarketplaceTests {
Marketplace::create(TestScenario::ctx(scenario));
}

/// Mint GAS and send it to BUYER.
/// Mint SUI and send it to BUYER.
fun mint_some_coin(scenario: &mut Scenario) {
TestScenario::next_tx(scenario, &ADMIN);
let coin = Coin::mint_for_testing<GAS>(1000, TestScenario::ctx(scenario));
let coin = Coin::mint_for_testing<SUI>(1000, TestScenario::ctx(scenario));
Transfer::transfer(coin, BUYER);
}

Expand All @@ -193,13 +193,13 @@ module NFTs::MarketplaceTests {
NFT::transfer(nft, SELLER);
}

// SELLER lists KITTY at the Marketplace for 100 GAS.
// SELLER lists KITTY at the Marketplace for 100 SUI.
fun list_kitty(scenario: &mut Scenario) {
TestScenario::next_tx(scenario, &SELLER);
let mkp = TestScenario::remove_object<Marketplace>(scenario);
let nft = TestScenario::remove_object<NFT<KITTY>>(scenario);

Marketplace::list<NFT<KITTY>, GAS>(&mut mkp, nft, 100, TestScenario::ctx(scenario));
Marketplace::list<NFT<KITTY>, SUI>(&mut mkp, nft, 100, TestScenario::ctx(scenario));
TestScenario::return_object(scenario, mkp);
}

Expand All @@ -214,10 +214,10 @@ module NFTs::MarketplaceTests {
TestScenario::next_tx(scenario, &SELLER);
{
let mkp = TestScenario::remove_object<Marketplace>(scenario);
let listing = TestScenario::remove_nested_object<Marketplace, Listing<NFT<KITTY>, GAS>>(scenario, &mkp);
let listing = TestScenario::remove_nested_object<Marketplace, Listing<NFT<KITTY>, SUI>>(scenario, &mkp);

// Do the delist operation on a Marketplace.
let nft = Marketplace::delist<NFT<KITTY>, GAS>(&mut mkp, listing, TestScenario::ctx(scenario));
let nft = Marketplace::delist<NFT<KITTY>, SUI>(&mut mkp, listing, TestScenario::ctx(scenario));
let kitten = NFT::burn<KITTY>(nft);

assert!(kitten.id == 1, 0);
Expand All @@ -240,10 +240,10 @@ module NFTs::MarketplaceTests {
TestScenario::next_tx(scenario, &BUYER);
{
let mkp = TestScenario::remove_object<Marketplace>(scenario);
let listing = TestScenario::remove_nested_object<Marketplace, Listing<NFT<KITTY>, GAS>>(scenario, &mkp);

let listing = TestScenario::remove_nested_object<Marketplace, Listing<NFT<KITTY>, SUI>>(scenario, &mkp);
// Do the delist operation on a Marketplace.
let nft = Marketplace::delist<NFT<KITTY>, GAS>(&mut mkp, listing, TestScenario::ctx(scenario));
let nft = Marketplace::delist<NFT<KITTY>, SUI>(&mut mkp, listing, TestScenario::ctx(scenario));
let _ = NFT::burn<KITTY>(nft);

TestScenario::return_object(scenario, mkp);
Expand All @@ -259,16 +259,16 @@ module NFTs::MarketplaceTests {
mint_kitty(scenario);
list_kitty(scenario);

// BUYER takes 100 GAS from his wallet and purchases KITTY.
// BUYER takes 100 SUI from his wallet and purchases KITTY.
TestScenario::next_tx(scenario, &BUYER);
{
let coin = TestScenario::remove_object<Coin<GAS>>(scenario);
let coin = TestScenario::remove_object<Coin<SUI>>(scenario);
let mkp = TestScenario::remove_object<Marketplace>(scenario);
let listing = TestScenario::remove_nested_object<Marketplace, Listing<NFT<KITTY>, GAS>>(scenario, &mkp);
let listing = TestScenario::remove_nested_object<Marketplace, Listing<NFT<KITTY>, SUI>>(scenario, &mkp);
let payment = Coin::withdraw(&mut coin, 100, TestScenario::ctx(scenario));

// Do the buy call and expect successful purchase.
let nft = Marketplace::buy<NFT<KITTY>, GAS>(&mut mkp, listing, payment);
let nft = Marketplace::buy<NFT<KITTY>, SUI>(&mut mkp, listing, payment);
let kitten = NFT::burn<KITTY>(nft);

assert!(kitten.id == 1, 0);
Expand All @@ -288,18 +288,18 @@ module NFTs::MarketplaceTests {
mint_kitty(scenario);
list_kitty(scenario);

// BUYER takes 100 GAS from his wallet and purchases KITTY.
// BUYER takes 100 SUI from his wallet and purchases KITTY.
TestScenario::next_tx(scenario, &BUYER);
{
let coin = TestScenario::remove_object<Coin<GAS>>(scenario);
let coin = TestScenario::remove_object<Coin<SUI>>(scenario);
let mkp = TestScenario::remove_object<Marketplace>(scenario);
let listing = TestScenario::remove_nested_object<Marketplace, Listing<NFT<KITTY>, GAS>>(scenario, &mkp);
let listing = TestScenario::remove_nested_object<Marketplace, Listing<NFT<KITTY>, SUI>>(scenario, &mkp);

// AMOUNT here is 10 while expected is 100.
let payment = Coin::withdraw(&mut coin, 10, TestScenario::ctx(scenario));

// Attempt to buy and expect failure purchase.
let nft = Marketplace::buy<NFT<KITTY>, GAS>(&mut mkp, listing, payment);
let nft = Marketplace::buy<NFT<KITTY>, SUI>(&mut mkp, listing, payment);
let _ = NFT::burn<KITTY>(nft);

TestScenario::return_object(scenario, mkp);
Expand Down
4 changes: 2 additions & 2 deletions sui_programmability/examples/nfts/sources/SharedAuction.move
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
module NFTs::SharedAuction {
use Sui::Coin::Coin;
use Sui::GAS::GAS;
use Sui::SUI::SUI;
use Sui::Transfer;
use Sui::TxContext::{Self,TxContext};

Expand All @@ -51,7 +51,7 @@ module NFTs::SharedAuction {
/// change of the auction state (if bid was high enough) or return
/// of the funds (if the bid was too low). This is executed by a
/// bidder.
public fun bid<T: key + store>(coin: Coin<GAS>, auction: &mut Auction<T>, ctx: &mut TxContext) {
public fun bid<T: key + store>(coin: Coin<SUI>, auction: &mut Auction<T>, ctx: &mut TxContext) {
let bidder = TxContext::sender(ctx);
AuctionLib::update_auction(auction, bidder, coin);
}
Expand Down
8 changes: 4 additions & 4 deletions sui_programmability/examples/nfts/tests/AuctionTests.move
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ module NFTs::AuctionTests {
use Std::Vector;

use Sui::Coin::{Self, Coin};
use Sui::GAS::GAS;
use Sui::SUI::SUI;
use Sui::ID::{Self, VersionedID};
use Sui::TestScenario::Self;
use Sui::TxContext::{Self, TxContext};
Expand All @@ -30,7 +30,7 @@ module NFTs::AuctionTests {
while (!Vector::is_empty(&bidders)) {
let bidder = Vector::pop_back(&mut bidders);
let coin = Coin::mint_for_testing(100, ctx);
Coin::transfer<GAS>(coin, bidder);
Coin::transfer<SUI>(coin, bidder);
};
}

Expand Down Expand Up @@ -71,7 +71,7 @@ module NFTs::AuctionTests {
// a transaction by the first bidder to create and put a bid
TestScenario::next_tx(scenario, &bidder1);
{
let coin = TestScenario::remove_object<Coin<GAS>>(scenario);
let coin = TestScenario::remove_object<Coin<SUI>>(scenario);

Auction::bid(coin, auction_id, auctioneer, TestScenario::ctx(scenario));
};
Expand All @@ -91,7 +91,7 @@ module NFTs::AuctionTests {
// bidder's)
TestScenario::next_tx(scenario, &bidder2);
{
let coin = TestScenario::remove_object<Coin<GAS>>(scenario);
let coin = TestScenario::remove_object<Coin<SUI>>(scenario);

Auction::bid(coin, auction_id, auctioneer, TestScenario::ctx(scenario));
};
Expand Down
10 changes: 5 additions & 5 deletions sui_programmability/examples/nfts/tests/SharedAuctionTests.move
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ module NFTs::SharedAuctionTests {
use Std::Vector;

use Sui::Coin::{Self, Coin};
use Sui::GAS::GAS;
use Sui::SUI::SUI;
use Sui::ID::VersionedID;
use Sui::TestScenario::Self;
use Sui::TxContext::{Self, TxContext};
Expand Down Expand Up @@ -34,7 +34,7 @@ module NFTs::SharedAuctionTests {
while (!Vector::is_empty(&bidders)) {
let bidder = Vector::pop_back(&mut bidders);
let coin = Coin::mint_for_testing(COIN_VALUE, ctx);
Coin::transfer<GAS>(coin, bidder);
Coin::transfer<SUI>(coin, bidder);
};
}

Expand Down Expand Up @@ -68,7 +68,7 @@ module NFTs::SharedAuctionTests {
// a transaction by the first bidder to put a bid
TestScenario::next_tx(scenario, &bidder1);
{
let coin = TestScenario::remove_object<Coin<GAS>>(scenario);
let coin = TestScenario::remove_object<Coin<SUI>>(scenario);
let auction = TestScenario::remove_object<Auction<SomeItemToSell>>(scenario);

SharedAuction::bid(coin, &mut auction, TestScenario::ctx(scenario));
Expand All @@ -81,7 +81,7 @@ module NFTs::SharedAuctionTests {
// bidder's)
TestScenario::next_tx(scenario, &bidder2);
{
let coin = TestScenario::remove_object<Coin<GAS>>(scenario);
let coin = TestScenario::remove_object<Coin<SUI>>(scenario);
let auction = TestScenario::remove_object<Auction<SomeItemToSell>>(scenario);

SharedAuction::bid(coin, &mut auction, TestScenario::ctx(scenario));
Expand All @@ -93,7 +93,7 @@ module NFTs::SharedAuctionTests {
// have been returned (as a result of the failed bid).
TestScenario::next_tx(scenario, &bidder2);
{
let coin = TestScenario::remove_object<Coin<GAS>>(scenario);
let coin = TestScenario::remove_object<Coin<SUI>>(scenario);

assert!(Coin::value(&coin) == COIN_VALUE, EWRONG_COIN_VALUE);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,26 @@
// SPDX-License-Identifier: Apache-2.0

/// Coin<Gas> is the token used to pay for gas in Sui
module Sui::GAS {
module Sui::SUI {
use Sui::Coin;
use Sui::Transfer;
use Sui::TxContext::{Self, TxContext};

/// Name of the coin
struct GAS has drop {}
struct SUI has drop {}

/// Register the token to acquire its `TreasuryCap`. Because
/// this is a module initializer, it ensures the currency only gets
/// registered once.
// TODO(https://github.com/MystenLabs/sui/issues/90): implement module initializers
fun init(ctx: &mut TxContext) {
// Get a treasury cap for the coin and give it to the transaction sender
let treasury_cap = Coin::create_currency(GAS{}, ctx);
let treasury_cap = Coin::create_currency(SUI{}, ctx);
Transfer::transfer(treasury_cap, TxContext::sender(ctx))
}

/// Transfer to a recipient
public fun transfer(c: Coin::Coin<GAS>, recipient: address, _ctx: &mut TxContext) {
public fun transfer(c: Coin::Coin<SUI>, recipient: address, _ctx: &mut TxContext) {
Coin::transfer(c, recipient)
}

Expand Down
Loading

0 comments on commit 44b5702

Please sign in to comment.