Skip to content

Commit 7c62b48

Browse files
authored
Merge pull request #71 from near-examples/fix-inconsistent-interfaces
Fix inconsistent interfaces
2 parents ee33444 + 5850bf8 commit 7c62b48

50 files changed

Lines changed: 760 additions & 824 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ near view $NFT_CONTRACT_ID nft_metadata
9393
### Minting Token
9494

9595
```bash=
96-
near call $NFT_CONTRACT_ID nft_mint '{"token_id": "token-1", "metadata": {"title": "My Non Fungible Team Token", "description": "The Team Most Certainly Goes :)", "media": "https://bafybeiftczwrtyr3k7a2k4vutd3amkwsmaqyhrdzlhvpt33dyjivufqusq.ipfs.dweb.link/goteam-gif.gif"}, "receiver_id": "'$MAIN_ACCOUNT'"}' --accountId $MAIN_ACCOUNT --amount 0.1
96+
near call $NFT_CONTRACT_ID nft_mint '{"token_id": "token-1", "token_metadata": {"title": "My Non Fungible Team Token", "description": "The Team Most Certainly Goes :)", "media": "https://bafybeiftczwrtyr3k7a2k4vutd3amkwsmaqyhrdzlhvpt33dyjivufqusq.ipfs.dweb.link/goteam-gif.gif"}, "token_owner_id": "'$MAIN_ACCOUNT'"}' --accountId $MAIN_ACCOUNT --amount 0.1
9797
```
9898

9999
After you've minted the token go to wallet.testnet.near.org to `your-account.testnet` and look in the collections tab and check out your new sample NFT!

integration-tests/Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ publish = false
55
edition = "2021"
66

77
[dev-dependencies]
8-
near-sdk = { version = "5.4.0", features = ["unit-testing"] }
9-
near-workspaces = { version = "0.14.1", features = ["unstable"] }
8+
near-sdk = { version = "5.11.0", features = ["unit-testing"] }
9+
near-workspaces = { version = "0.18.0", features = ["unstable"] }
1010
tokio = { version = "1.12.0", features = ["full"] }
1111
serde_json = "1"
1212

integration-tests/src/helpers.rs

Lines changed: 37 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
1+
use near_sdk::Gas;
2+
use near_workspaces::{
3+
types::{AccountDetails, NearToken},
4+
Account, Contract,
5+
};
16
use serde_json::json;
2-
use near_workspaces::{types::{NearToken, AccountDetails}, Account, Contract};
37

48
pub const DEFAULT_DEPOSIT: u128 = 10000000000000000000000;
59
pub const ONE_YOCTO_NEAR: NearToken = NearToken::from_yoctonear(1);
@@ -8,23 +12,24 @@ pub async fn mint_nft(
812
user: &Account,
913
nft_contract: &Contract,
1014
token_id: &str,
11-
) -> Result<(), Box<dyn std::error::Error>> {
15+
) -> Result<(), Box<dyn std::error::Error>> {
1216
let request_payload = json!({
1317
"token_id": token_id,
14-
"receiver_id": user.id(),
15-
"metadata": {
18+
"token_owner_id": user.id(),
19+
"token_metadata": {
1620
"title": "Grumpy Cat",
1721
"description": "Not amused.",
1822
"media": "https://www.adamsdrafting.com/wp-content/uploads/2018/06/More-Grumpy-Cat.jpg"
1923
},
2024
});
2125

22-
let _ = user.call(nft_contract.id(), "nft_mint")
26+
let _ = user
27+
.call(nft_contract.id(), "nft_mint")
2328
.args_json(request_payload)
2429
.deposit(NearToken::from_yoctonear(DEFAULT_DEPOSIT))
2530
.transact()
2631
.await;
27-
32+
2833
Ok(())
2934
}
3035

@@ -34,13 +39,14 @@ pub async fn approve_nft(
3439
nft_contract: &Contract,
3540
token_id: &str,
3641
) -> Result<(), Box<dyn std::error::Error>> {
37-
let request_payload = json!({
42+
let request_payload = json!({
3843
"token_id": token_id,
3944
"account_id": market_contract.id(),
4045
"msg": serde_json::Value::Null,
4146
});
4247

43-
let _ = user.call(nft_contract.id(), "nft_approve")
48+
let _ = user
49+
.call(nft_contract.id(), "nft_approve")
4450
.args_json(request_payload)
4551
.deposit(NearToken::from_yoctonear(DEFAULT_DEPOSIT))
4652
.transact()
@@ -55,8 +61,9 @@ pub async fn pay_for_storage(
5561
amount: NearToken,
5662
) -> Result<(), Box<dyn std::error::Error>> {
5763
let request_payload = json!({});
58-
59-
let _ = user.call(market_contract.id(), "storage_deposit")
64+
65+
let _ = user
66+
.call(market_contract.id(), "storage_deposit")
6067
.args_json(request_payload)
6168
.deposit(amount)
6269
.transact()
@@ -70,7 +77,7 @@ pub async fn place_nft_for_sale(
7077
market_contract: &Contract,
7178
nft_contract: &Contract,
7279
token_id: &str,
73-
approval_id: u32,
80+
approval_id: u64,
7481
price: &NearToken,
7582
) -> Result<(), Box<dyn std::error::Error>> {
7683
let request_payload = json!({
@@ -79,20 +86,21 @@ pub async fn place_nft_for_sale(
7986
"approval_id": approval_id,
8087
"sale_conditions": NearToken::as_yoctonear(price).to_string(),
8188
});
82-
let _ = user.call(market_contract.id(), "list_nft_for_sale")
89+
let _ = user
90+
.call(market_contract.id(), "list_nft_for_sale")
8391
.args_json(request_payload)
84-
.max_gas()
85-
.deposit(NearToken::from_yoctonear(DEFAULT_DEPOSIT))
92+
.gas(Gas::from_tgas(100))
8693
.transact()
8794
.await;
8895

8996
Ok(())
9097
}
9198

92-
pub async fn get_user_balance(
93-
user: &Account,
94-
) -> NearToken {
95-
let details: AccountDetails = user.view_account().await.expect("Account has to have some balance");
99+
pub async fn get_user_balance(user: &Account) -> NearToken {
100+
let details: AccountDetails = user
101+
.view_account()
102+
.await
103+
.expect("Account has to have some balance");
96104
details.balance
97105
}
98106

@@ -101,14 +109,15 @@ pub async fn purchase_listed_nft(
101109
market_contract: &Contract,
102110
nft_contract: &Contract,
103111
token_id: &str,
104-
offer_price: NearToken
112+
offer_price: NearToken,
105113
) -> Result<(), Box<dyn std::error::Error>> {
106-
let request_payload = json!({
114+
let request_payload = json!({
107115
"token_id": token_id,
108116
"nft_contract_id": nft_contract.id(),
109117
});
110118

111-
let _ = bidder.call(market_contract.id(), "offer")
119+
let _ = bidder
120+
.call(market_contract.id(), "offer")
112121
.args_json(request_payload)
113122
.max_gas()
114123
.deposit(offer_price)
@@ -124,19 +133,20 @@ pub async fn transfer_nft(
124133
nft_contract: &Contract,
125134
token_id: &str,
126135
) -> Result<(), Box<dyn std::error::Error>> {
127-
let request_payload = json!({
136+
let request_payload = json!({
128137
"token_id": token_id,
129138
"receiver_id": receiver.id(),
130139
"approval_id": 1 as u64,
131140
});
132141

133-
let _ = sender.call(nft_contract.id(), "nft_transfer")
142+
let _ = sender
143+
.call(nft_contract.id(), "nft_transfer")
134144
.args_json(request_payload)
135145
.max_gas()
136146
.deposit(ONE_YOCTO_NEAR)
137147
.transact()
138148
.await;
139-
149+
140150
Ok(())
141151
}
142152

@@ -155,10 +165,7 @@ pub async fn get_nft_token_info(
155165
Ok(token_info)
156166
}
157167

158-
pub fn round_to_near_dp(
159-
amount: u128,
160-
sf: u128,
161-
) -> String {
162-
let near_amount = amount as f64 / 1_000_000_000_000_000_000_000_000.0; // yocto in 1 NEAR
168+
pub fn round_to_near_dp(amount: u128, sf: u128) -> String {
169+
let near_amount = amount as f64 / 1_000_000_000_000_000_000_000_000.0; // yocto in 1 NEAR
163170
return format!("{:.1$}", near_amount, sf as usize);
164-
}
171+
}

integration-tests/src/tests.rs

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -99,8 +99,8 @@ async fn test_nft_mint_call(
9999
) -> Result<(), Box<dyn std::error::Error>> {
100100
let request_payload = json!({
101101
"token_id": "1",
102-
"receiver_id": user.id(),
103-
"metadata": {
102+
"token_owner_id": user.id(),
103+
"token_metadata": {
104104
"title": "LEEROYYYMMMJENKINSSS",
105105
"description": "Alright time's up, let's do this.",
106106
"media": "https://external-content.duckduckgo.com/iu/?u=https%3A%2F%2Ftse3.mm.bing.net%2Fth%3Fid%3DOIP.Fhp4lHufCdTzTeGCAblOdgHaF7%26pid%3DApi&f=1"
@@ -182,15 +182,10 @@ async fn test_sell_nft_listed_on_marketplace(
182182
) -> Result<(), Box<dyn std::error::Error>> {
183183
let token_id = "4";
184184
let approval_id = 0;
185-
let sale_price: NearToken = NearToken::from_yoctonear(10000000000000000000000000);
185+
let sale_price: NearToken = NearToken::from_near(1);
186186

187187
helpers::mint_nft(seller, nft_contract, token_id).await?;
188-
helpers::pay_for_storage(
189-
seller,
190-
market_contract,
191-
NearToken::from_yoctonear(1000000000000000000000000),
192-
)
193-
.await?;
188+
helpers::pay_for_storage(seller, market_contract, NearToken::from_millinear(10)).await?;
194189
helpers::approve_nft(market_contract, seller, nft_contract, token_id).await?;
195190
helpers::place_nft_for_sale(
196191
seller,
@@ -392,8 +387,8 @@ async fn test_reselling_and_royalties(
392387
// mint with royalties
393388
let request_payload = json!({
394389
"token_id": token_id,
395-
"receiver_id": user.id(),
396-
"metadata": {
390+
"token_owner_id": user.id(),
391+
"token_metadata": {
397392
"title": "Grumpy Cat",
398393
"description": "Not amused.",
399394
"media": "https://www.adamsdrafting.com/wp-content/uploads/2018/06/More-Grumpy-Cat.jpg"
@@ -555,8 +550,8 @@ async fn test_royalties_exceeding_100_percents(
555550
// mint with royalties
556551
let request_payload = json!({
557552
"token_id": token_id,
558-
"receiver_id": user.id(),
559-
"metadata": {
553+
"token_owner_id": user.id(),
554+
"token_metadata": {
560555
"title": "Grumpy Cat",
561556
"description": "Not amused.",
562557
"media": "https://www.adamsdrafting.com/wp-content/uploads/2018/06/More-Grumpy-Cat.jpg"

market-contract/Cargo.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@ edition = "2021"
88
crate-type = ["cdylib", "rlib"]
99

1010
[dependencies]
11-
near-sdk = { version = "5.4.0", features = ["legacy"] }
11+
near-sdk = { version = "5.11.0", features = ["legacy"] }
1212

1313
[dev-dependencies]
14-
near-sdk = { version = "5.4.0", features = ["unit-testing"] }
15-
near-workspaces = { version = "0.14.1", features = ["unstable"] }
14+
near-sdk = { version = "5.11.0", features = ["unit-testing"] }
15+
near-workspaces = { version = "0.18.0", features = ["unstable"] }
1616
tokio = { version = "1.12.0", features = ["full"] }
1717
serde_json = "1"
1818

market-contract/src/external.rs

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,22 +9,17 @@ trait ExtContract {
99
fn nft_transfer_payout(
1010
&mut self,
1111
receiver_id: AccountId, //purchaser (person to transfer the NFT to)
12-
token_id: TokenId, //token ID to transfer
13-
approval_id: u32, //market contract's approval ID in order to transfer the token on behalf of the owner
14-
memo: String, //memo (to include some context)
12+
token_id: TokenId, //token ID to transfer
13+
approval_id: u64, //market contract's approval ID in order to transfer the token on behalf of the owner
14+
memo: String, //memo (to include some context)
1515
/*
1616
the price that the token was purchased for. This will be used in conjunction with the royalty percentages
17-
for the token in order to determine how much money should go to which account.
17+
for the token in order to determine how much money should go to which account.
1818
*/
1919
balance: NearToken,
2020
//the maximum amount of accounts the market can payout at once (this is limited by GAS)
21-
max_len_payout: u32,
21+
max_len_payout: u32,
2222
);
2323
fn nft_token(&self, token_id: TokenId);
24-
fn nft_is_approved(
25-
&self,
26-
token_id: TokenId,
27-
approved_account_id: AccountId,
28-
approval_id: u32,
29-
);
30-
}
24+
fn nft_is_approved(&self, token_id: TokenId, approved_account_id: AccountId, approval_id: u64);
25+
}

market-contract/src/nft_callbacks.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,14 @@ use crate::*;
55
/*
66
trait that will be used as the callback from the NFT contract. When nft_approve is
77
called, it will fire a cross contract call to this marketplace and this is the function
8-
that is invoked.
8+
that is invoked.
99
*/
1010
trait NonFungibleTokenApprovalsReceiver {
1111
fn nft_on_approve(
1212
&mut self,
1313
token_id: TokenId,
1414
owner_id: AccountId,
15-
approval_id: u32,
15+
approval_id: u64,
1616
msg: String,
1717
);
1818
}
@@ -24,7 +24,7 @@ impl NonFungibleTokenApprovalsReceiver for Contract {
2424
&mut self,
2525
token_id: TokenId,
2626
owner_id: AccountId,
27-
approval_id: u32,
27+
approval_id: u64,
2828
msg: String,
2929
) {
3030
/*

0 commit comments

Comments
 (0)