Skip to content

Commit 0e1281f

Browse files
Correct the "tests and docs" test in the documentation. (#4250)
## Motivation The merging of the PR #4210 led to some problems because the `Operation` and `Abi` types are no longer accessible when publishing. The use of example types is fine only for tests, not for benchmarks. ## Proposal Put back the `NativeFungibleTokenAbi` and `FungibleTokenAbi` in the `linera-sdk::abis::fungible` and rename as needed. ## Test Plan The `script/test_publish.sh` was used. ## Release Plan - Nothing to do / These changes follow the usual release cycle. ## Links None.
1 parent 58ec78f commit 0e1281f

File tree

19 files changed

+182
-186
lines changed

19 files changed

+182
-186
lines changed

examples/amm/src/contract.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,9 @@
66
mod state;
77

88
use amm::{AmmAbi, Message, Operation, Parameters};
9-
use fungible::{Account, FungibleTokenAbi};
9+
use fungible::Account;
1010
use linera_sdk::{
11+
abis::fungible::{FungibleOperation, FungibleResponse, FungibleTokenAbi},
1112
linera_base_types::{AccountOwner, Amount, ApplicationId, ChainId, WithContractAbi},
1213
views::{RootView, View},
1314
Contract, ContractRuntime,
@@ -673,7 +674,7 @@ impl AmmContract {
673674
token_idx: u32,
674675
) {
675676
let token = self.fungible_id(token_idx);
676-
let operation = fungible::Operation::Transfer {
677+
let operation = FungibleOperation::Transfer {
677678
owner: source_owner,
678679
amount,
679680
target_account,
@@ -683,10 +684,10 @@ impl AmmContract {
683684
}
684685

685686
fn balance(&mut self, owner: &AccountOwner, token_idx: u32) -> Amount {
686-
let balance = fungible::Operation::Balance { owner: *owner };
687+
let balance = FungibleOperation::Balance { owner: *owner };
687688
let token = self.fungible_id(token_idx);
688689
match self.runtime.call_application(true, token, &balance) {
689-
fungible::FungibleResponse::Balance(balance) => balance,
690+
FungibleResponse::Balance(balance) => balance,
690691
response => panic!("Unexpected response from fungible token application: {response:?}"),
691692
}
692693
}

examples/crowd-funding/src/contract.rs

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ mod state;
88
use crowd_funding::{CrowdFundingAbi, InstantiationArgument, Message, Operation};
99
use fungible::{Account, FungibleTokenAbi};
1010
use linera_sdk::{
11+
abis::fungible::FungibleOperation,
1112
linera_base_types::{AccountOwner, Amount, ApplicationId, WithContractAbi},
1213
views::{RootView, View},
1314
Contract, ContractRuntime,
@@ -100,7 +101,7 @@ impl CrowdFundingContract {
100101
// TODO(#589): Simplify this when the messaging system guarantees atomic delivery
101102
// of all messages created in the same operation/message.
102103
let target_account = Account { chain_id, owner };
103-
let call = fungible::Operation::Transfer {
104+
let call = FungibleOperation::Transfer {
104105
owner,
105106
amount,
106107
target_account,
@@ -195,11 +196,9 @@ impl CrowdFundingContract {
195196
fn balance(&mut self) -> Amount {
196197
let owner = self.runtime.application_id().into();
197198
let fungible_id = self.fungible_id();
198-
let response = self.runtime.call_application(
199-
true,
200-
fungible_id,
201-
&fungible::Operation::Balance { owner },
202-
);
199+
let response =
200+
self.runtime
201+
.call_application(true, fungible_id, &FungibleOperation::Balance { owner });
203202
match response {
204203
fungible::FungibleResponse::Balance(balance) => balance,
205204
response => panic!("Unexpected response from fungible token application: {response:?}"),
@@ -212,7 +211,7 @@ impl CrowdFundingContract {
212211
chain_id: self.runtime.chain_id(),
213212
owner,
214213
};
215-
let transfer = fungible::Operation::Transfer {
214+
let transfer = FungibleOperation::Transfer {
216215
owner: self.runtime.application_id().into(),
217216
amount,
218217
target_account,
@@ -227,7 +226,7 @@ impl CrowdFundingContract {
227226
chain_id: self.runtime.chain_id(),
228227
owner: self.runtime.application_id().into(),
229228
};
230-
let transfer = fungible::Operation::Transfer {
229+
let transfer = FungibleOperation::Transfer {
231230
owner,
232231
amount,
233232
target_account,

examples/fungible/src/contract.rs

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66
mod state;
77

88
use fungible::{
9-
Account, FungibleResponse, FungibleTokenAbi, InitialState, Message, Operation, Parameters,
9+
Account, FungibleOperation, FungibleResponse, FungibleTokenAbi, InitialState, Message,
10+
Parameters,
1011
};
1112
use linera_sdk::{
1213
linera_base_types::{AccountOwner, Amount, WithContractAbi},
@@ -56,17 +57,17 @@ impl Contract for FungibleTokenContract {
5657

5758
async fn execute_operation(&mut self, operation: Self::Operation) -> Self::Response {
5859
match operation {
59-
Operation::Balance { owner } => {
60+
FungibleOperation::Balance { owner } => {
6061
let balance = self.state.balance_or_default(&owner).await;
6162
FungibleResponse::Balance(balance)
6263
}
6364

64-
Operation::TickerSymbol => {
65+
FungibleOperation::TickerSymbol => {
6566
let params = self.runtime.application_parameters();
6667
FungibleResponse::TickerSymbol(params.ticker_symbol)
6768
}
6869

69-
Operation::Approve {
70+
FungibleOperation::Approve {
7071
owner,
7172
spender,
7273
allowance,
@@ -78,7 +79,7 @@ impl Contract for FungibleTokenContract {
7879
FungibleResponse::Ok
7980
}
8081

81-
Operation::Transfer {
82+
FungibleOperation::Transfer {
8283
owner,
8384
amount,
8485
target_account,
@@ -92,7 +93,7 @@ impl Contract for FungibleTokenContract {
9293
FungibleResponse::Ok
9394
}
9495

95-
Operation::TransferFrom {
96+
FungibleOperation::TransferFrom {
9697
owner,
9798
spender,
9899
amount,
@@ -109,7 +110,7 @@ impl Contract for FungibleTokenContract {
109110
FungibleResponse::Ok
110111
}
111112

112-
Operation::Claim {
113+
FungibleOperation::Claim {
113114
source_account,
114115
amount,
115116
target_account,

examples/fungible/src/lib.rs

Lines changed: 3 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,9 @@
33

44
/* ABI of the Fungible Token Example Application */
55

6-
use async_graphql::{scalar, Request, Response};
6+
use async_graphql::scalar;
77
pub use linera_sdk::abis::fungible::*;
8-
use linera_sdk::{
9-
abi::{ContractAbi, ServiceAbi},
10-
graphql::GraphQLMutationRoot,
11-
linera_base_types::{AccountOwner, Amount},
12-
};
8+
use linera_sdk::linera_base_types::{AccountOwner, Amount};
139
use serde::{Deserialize, Serialize};
1410
#[cfg(all(any(test, feature = "test"), not(target_arch = "wasm32")))]
1511
use {
@@ -65,71 +61,6 @@ impl OwnerSpender {
6561
}
6662
}
6763

68-
/// An ABI for applications that implement a fungible token.
69-
pub struct FungibleTokenAbi;
70-
71-
impl ContractAbi for FungibleTokenAbi {
72-
type Operation = Operation;
73-
type Response = FungibleResponse;
74-
}
75-
76-
impl ServiceAbi for FungibleTokenAbi {
77-
type Query = Request;
78-
type QueryResponse = Response;
79-
}
80-
81-
/// An operation
82-
#[derive(Debug, Deserialize, Serialize, GraphQLMutationRoot)]
83-
pub enum Operation {
84-
/// Requests an account balance.
85-
Balance {
86-
/// Owner to query the balance for
87-
owner: AccountOwner,
88-
},
89-
/// Requests this fungible token's ticker symbol.
90-
TickerSymbol,
91-
/// Approve the transfer of tokens
92-
Approve {
93-
/// Owner to transfer from
94-
owner: AccountOwner,
95-
/// The spender account
96-
spender: AccountOwner,
97-
/// Maximum amount to be transferred
98-
allowance: Amount,
99-
},
100-
/// Transfers tokens from a (locally owned) account to a (possibly remote) account.
101-
Transfer {
102-
/// Owner to transfer from
103-
owner: AccountOwner,
104-
/// Amount to be transferred
105-
amount: Amount,
106-
/// Target account to transfer the amount to
107-
target_account: Account,
108-
},
109-
/// Transfers tokens from a (locally owned) account to a (possibly remote) account by using the allowance.
110-
TransferFrom {
111-
/// Owner to transfer from
112-
owner: AccountOwner,
113-
/// The spender of the amount.
114-
spender: AccountOwner,
115-
/// Amount to be transferred
116-
amount: Amount,
117-
/// Target account to transfer the amount to
118-
target_account: Account,
119-
},
120-
/// Same as `Transfer` but the source account may be remote. Depending on its
121-
/// configuration, the target chain may take time or refuse to process
122-
/// the message.
123-
Claim {
124-
/// Source account to claim amount from
125-
source_account: Account,
126-
/// Amount to be claimed
127-
amount: Amount,
128-
/// Target account to claim the amount into
129-
target_account: Account,
130-
},
131-
}
132-
13364
/// Creates a fungible token application and distributes `initial_amounts` to new individual
13465
/// chains.
13566
#[cfg(all(any(test, feature = "test"), not(target_arch = "wasm32")))]
@@ -168,7 +99,7 @@ pub async fn create_with_accounts(
16899
.add_block(|block| {
169100
block.with_operation(
170101
application_id,
171-
Operation::Claim {
102+
FungibleOperation::Claim {
172103
source_account: Account {
173104
chain_id: token_chain.id(),
174105
owner: *account,

examples/fungible/src/service.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,9 @@ mod state;
88
use std::sync::Arc;
99

1010
use async_graphql::{EmptySubscription, Object, Request, Response, Schema};
11-
use fungible::{Operation, OwnerSpender, Parameters};
11+
use fungible::{OwnerSpender, Parameters};
1212
use linera_sdk::{
13+
abis::fungible::FungibleOperation,
1314
graphql::GraphQLMutationRoot,
1415
linera_base_types::{AccountOwner, Amount, WithServiceAbi},
1516
views::{MapView, View},
@@ -46,7 +47,7 @@ impl Service for FungibleTokenService {
4647
async fn handle_query(&self, request: Request) -> Response {
4748
let schema = Schema::build(
4849
self.clone(),
49-
Operation::mutation_root(self.runtime.clone()),
50+
FungibleOperation::mutation_root(self.runtime.clone()),
5051
EmptySubscription,
5152
)
5253
.finish();

examples/fungible/tests/cross_chain.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,9 @@
55
66
#![cfg(not(target_arch = "wasm32"))]
77

8-
use fungible::{
9-
Account, FungibleTokenAbi, InitialState, InitialStateBuilder, Operation, Parameters,
10-
};
8+
use fungible::{Account, FungibleTokenAbi, InitialState, InitialStateBuilder, Parameters};
119
use linera_sdk::{
10+
abis::fungible::FungibleOperation,
1211
linera_base_types::{AccountOwner, Amount},
1312
test::{MessageAction, TestValidator},
1413
};
@@ -43,7 +42,7 @@ async fn test_cross_chain_transfer() {
4342
.add_block(|block| {
4443
block.with_operation(
4544
application_id,
46-
Operation::Transfer {
45+
FungibleOperation::Transfer {
4746
owner: sender_account,
4847
amount: transfer_amount,
4948
target_account: Account {
@@ -97,7 +96,7 @@ async fn test_bouncing_tokens() {
9796
.add_block(|block| {
9897
block.with_operation(
9998
application_id,
100-
Operation::Transfer {
99+
FungibleOperation::Transfer {
101100
owner: sender_account,
102101
amount: transfer_amount,
103102
target_account: Account {

examples/matching-engine/src/contract.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ impl MatchingEngineContract {
191191
target_account: Account,
192192
token_idx: u32,
193193
) {
194-
let transfer = fungible::Operation::Transfer {
194+
let transfer = fungible::FungibleOperation::Transfer {
195195
owner,
196196
amount,
197197
target_account,

examples/native-fungible/src/contract.rs

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,14 @@
33

44
#![cfg_attr(target_arch = "wasm32", no_main)]
55

6-
use fungible::{FungibleResponse, InitialState, Parameters};
76
use linera_sdk::{
7+
abis::fungible::{
8+
FungibleResponse, InitialState, NativeFungibleOperation, NativeFungibleTokenAbi, Parameters,
9+
},
810
linera_base_types::{Account, AccountOwner, ChainId, WithContractAbi},
911
Contract, ContractRuntime,
1012
};
11-
use native_fungible::{Message, NativeFungibleTokenAbi, Operation, TICKER_SYMBOL};
13+
use native_fungible::{Message, TICKER_SYMBOL};
1214

1315
pub struct NativeFungibleTokenContract {
1416
runtime: ContractRuntime<Self>,
@@ -47,14 +49,16 @@ impl Contract for NativeFungibleTokenContract {
4749

4850
async fn execute_operation(&mut self, operation: Self::Operation) -> Self::Response {
4951
match operation {
50-
Operation::Balance { owner } => {
52+
NativeFungibleOperation::Balance { owner } => {
5153
let balance = self.runtime.owner_balance(owner);
5254
FungibleResponse::Balance(balance)
5355
}
5456

55-
Operation::TickerSymbol => FungibleResponse::TickerSymbol(String::from(TICKER_SYMBOL)),
57+
NativeFungibleOperation::TickerSymbol => {
58+
FungibleResponse::TickerSymbol(String::from(TICKER_SYMBOL))
59+
}
5660

57-
Operation::Transfer {
61+
NativeFungibleOperation::Transfer {
5862
owner,
5963
amount,
6064
target_account,
@@ -72,7 +76,7 @@ impl Contract for NativeFungibleTokenContract {
7276
FungibleResponse::Ok
7377
}
7478

75-
Operation::Claim {
79+
NativeFungibleOperation::Claim {
7680
source_account,
7781
amount,
7882
target_account,

0 commit comments

Comments
 (0)