Skip to content

Commit ae0aa00

Browse files
authored
Merge pull request #455 from Concordium/rust-sdk-6
Update rust sdk to support P8
2 parents 165a57f + 39d916f commit ae0aa00

File tree

8 files changed

+42
-422
lines changed

8 files changed

+42
-422
lines changed

.github/workflows/linter.yml

Lines changed: 16 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -64,11 +64,9 @@ jobs:
6464
submodules: recursive
6565

6666
- name: Install nightly toolchain with rustfmt available
67-
uses: actions-rs/toolchain@v1
67+
uses: actions-rust-lang/setup-rust-toolchain@v1
6868
with:
69-
profile: minimal
7069
toolchain: ${{ env.RUST_FMT }}
71-
override: true
7270
components: rustfmt
7371

7472
- name: Run cargo fmt
@@ -95,11 +93,9 @@ jobs:
9593
submodules: recursive
9694

9795
- name: Install Rust
98-
uses: actions-rs/toolchain@v1
96+
uses: actions-rust-lang/setup-rust-toolchain@v1
9997
with:
100-
profile: minimal
10198
toolchain: ${{ env.RUST_VERSION }}
102-
override: true
10399

104100
- name: Run cargo doc
105101
working-directory: ${{ matrix.crates }}
@@ -118,12 +114,10 @@ jobs:
118114
submodules: recursive
119115

120116
- name: Install toolchain
121-
uses: actions-rs/toolchain@v1
117+
uses: actions-rust-lang/setup-rust-toolchain@v1
122118
with:
123119
toolchain: ${{ env.RUST_VERSION }}
124-
125-
- name: Install Wasm target
126-
run: rustup target install wasm32-unknown-unknown
120+
target: wasm32-unknown-unknown
127121

128122
- name: Run internal wasm unit test
129123
working-directory: concordium-std
@@ -157,12 +151,10 @@ jobs:
157151
submodules: recursive
158152

159153
- name: Install toolchain with clippy available
160-
uses: actions-rs/toolchain@v1
154+
uses: actions-rust-lang/setup-rust-toolchain@v1
161155
with:
162-
profile: minimal
163156
toolchain: ${{ env.RUST_VERSION }}
164157
target: ${{ matrix.target }}
165-
override: true
166158
components: clippy
167159

168160
- name: Run cargo clippy
@@ -197,12 +189,10 @@ jobs:
197189
submodules: recursive
198190

199191
- name: Install toolchain with clippy available
200-
uses: actions-rs/toolchain@v1
192+
uses: actions-rust-lang/setup-rust-toolchain@v1
201193
with:
202-
profile: minimal
203194
toolchain: ${{ env.RUST_VERSION }}
204195
target: ${{ matrix.target }}
205-
override: true
206196
components: clippy
207197

208198
- name: Run cargo clippy
@@ -234,12 +224,10 @@ jobs:
234224
submodules: recursive
235225

236226
- name: Install toolchain with clippy available
237-
uses: actions-rs/toolchain@v1
227+
uses: actions-rust-lang/setup-rust-toolchain@v1
238228
with:
239-
profile: minimal
240229
toolchain: ${{ env.RUST_VERSION }}
241230
target: ${{ matrix.target }}
242-
override: true
243231
components: clippy
244232

245233
- name: Run cargo clippy
@@ -273,12 +261,10 @@ jobs:
273261
submodules: recursive
274262

275263
- name: Install toolchain with clippy available
276-
uses: actions-rs/toolchain@v1
264+
uses: actions-rust-lang/setup-rust-toolchain@v1
277265
with:
278-
profile: minimal
279266
toolchain: ${{ env.RUST_VERSION }}
280267
target: ${{ matrix.target }}
281-
override: true
282268
components: clippy
283269

284270
- name: Run cargo clippy, but only for wasm32 target
@@ -298,12 +284,10 @@ jobs:
298284
submodules: recursive
299285

300286
- name: Install nightly toolchain with check available
301-
uses: actions-rs/toolchain@v1
287+
uses: actions-rust-lang/setup-rust-toolchain@v1
302288
with:
303-
profile: minimal
304289
toolchain: nightly
305290
target: wasm32-unknown-unknown
306-
override: true
307291

308292
- name: Run no-std build concordium-std
309293
working-directory: concordium-std
@@ -345,12 +329,10 @@ jobs:
345329
submodules: recursive
346330

347331
- name: Install nightly toolchain with check available
348-
uses: actions-rs/toolchain@v1
332+
uses: actions-rust-lang/setup-rust-toolchain@v1
349333
with:
350-
profile: minimal
351334
toolchain: nightly
352335
target: ${{ matrix.target }}
353-
override: true
354336

355337
- name: Run cargo check with no-std
356338
uses: actions-rs/cargo@v1
@@ -381,12 +363,10 @@ jobs:
381363
submodules: recursive
382364

383365
- name: Install toolchain
384-
uses: actions-rs/toolchain@v1
366+
uses: actions-rust-lang/setup-rust-toolchain@v1
385367
with:
386-
profile: minimal
387368
toolchain: ${{ env.RUST_VERSION }}
388369
target: ${{ matrix.target }}
389-
override: true
390370

391371
- name: Run cargo build with crypto-primitives feature
392372
uses: actions-rs/cargo@v1
@@ -441,12 +421,10 @@ jobs:
441421
submodules: recursive
442422

443423
- name: Install toolchain with clippy available
444-
uses: actions-rs/toolchain@v1
424+
uses: actions-rust-lang/setup-rust-toolchain@v1
445425
with:
446-
profile: minimal
447426
toolchain: ${{ env.RUST_VERSION }}
448427
target: ${{ matrix.target }}
449-
override: true
450428
components: clippy
451429

452430
- name: Run cargo clippy with schema and tests
@@ -478,12 +456,10 @@ jobs:
478456
submodules: recursive
479457

480458
- name: Install toolchain
481-
uses: actions-rs/toolchain@v1
459+
uses: actions-rust-lang/setup-rust-toolchain@v1
482460
with:
483-
profile: minimal
484461
toolchain: ${{ env.RUST_VERSION }}
485462
target: ${{ matrix.target }}
486-
override: true
487463

488464
- name: Run cargo test
489465
uses: actions-rs/cargo@v1
@@ -514,12 +490,10 @@ jobs:
514490
submodules: recursive
515491

516492
- name: Install toolchain
517-
uses: actions-rs/toolchain@v1
493+
uses: actions-rust-lang/setup-rust-toolchain@v1
518494
with:
519-
profile: minimal
520495
toolchain: ${{ env.RUST_VERSION }}
521496
target: ${{ matrix.target }}
522-
override: true
523497

524498
- name: Run cargo test
525499
uses: actions-rs/cargo@v1
@@ -534,9 +508,6 @@ jobs:
534508
needs: [rustfmt, clippy-schema]
535509
strategy:
536510
matrix:
537-
target:
538-
- x86_64-unknown-linux-gnu
539-
540511
crates:
541512
- examples/voting
542513
- examples/eSealing
@@ -575,15 +546,10 @@ jobs:
575546
submodules: recursive
576547

577548
- name: Install toolchain
578-
uses: actions-rs/toolchain@v1
549+
uses: actions-rust-lang/setup-rust-toolchain@v1
579550
with:
580-
profile: minimal
581551
toolchain: ${{ env.RUST_VERSION_TESTING_LIBRARY }}
582-
target: ${{ matrix.target }}
583-
override: true
584-
585-
- name: Install Wasm target
586-
run: rustup target install wasm32-unknown-unknown
552+
target: wasm32-unknown-unknown
587553

588554
- name: Download and install Cargo Concordium
589555
run: |

concordium-std/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -393,7 +393,7 @@
393393
//! [test_infrastructure]: ./test_infrastructure/index.html
394394
//! [concordium_smart_contract_testing]: https://docs.rs/concordium-smart-contract-testing
395395
396-
#![cfg_attr(not(feature = "std"), no_std, feature(core_intrinsics))]
396+
#![cfg_attr(not(feature = "std"), no_std, allow(internal_features), feature(core_intrinsics))]
397397

398398
#[cfg(not(feature = "std"))]
399399
pub extern crate alloc;

concordium-std/src/test_infrastructure.rs

Lines changed: 0 additions & 144 deletions
Original file line numberDiff line numberDiff line change
@@ -1926,147 +1926,3 @@ pub fn concordium_qc<A: Testable>(num_tests: u64, f: A) {
19261926
pub fn concordium_qc<A: Testable>(num_tests: u64, f: A) {
19271927
QuickCheck::new().tests(num_tests).max_tests(QUICKCHECK_MAX_WITH_DISCARDED_TESTS).quickcheck(f)
19281928
}
1929-
1930-
#[cfg(test)]
1931-
#[allow(deprecated)]
1932-
mod test {
1933-
use crate::{cell::RefCell, rc::Rc, test_infrastructure::TestStateEntry, HasStateEntry};
1934-
use concordium_contracts_common::{Read, Seek, SeekFrom, Write};
1935-
1936-
#[test]
1937-
fn test_testhost_balance_queries_reflect_transfers() {
1938-
use super::*;
1939-
let mut host = TestHost::new((), TestStateBuilder::new());
1940-
1941-
let self_address = ContractAddress::new(0, 0);
1942-
host.set_self_address(self_address);
1943-
host.set_self_balance(Amount::from_micro_ccd(3000));
1944-
1945-
let account = AccountAddress([0; 32]);
1946-
let account_balance =
1947-
AccountBalance::new(Amount::zero(), Amount::zero(), Amount::zero()).unwrap();
1948-
host.setup_query_account_balance(account, account_balance);
1949-
1950-
host.invoke_transfer(&account, Amount::from_micro_ccd(2000))
1951-
.expect("Transferring should succeed");
1952-
1953-
let account_new_balance = host.account_balance(account).expect("Should succeed");
1954-
let self_new_balance = host.contract_balance(self_address).expect("Should succeed");
1955-
1956-
assert_eq!(account_new_balance.total, Amount::from_micro_ccd(2000));
1957-
assert_eq!(self_new_balance, Amount::from_micro_ccd(1000));
1958-
}
1959-
1960-
#[test]
1961-
fn test_testhost_balance_queries_reflect_invoke() {
1962-
use super::*;
1963-
let mut host = TestHost::new((), TestStateBuilder::new());
1964-
1965-
let self_address = ContractAddress::new(0, 0);
1966-
host.set_self_address(self_address);
1967-
host.set_self_balance(Amount::from_micro_ccd(3000));
1968-
1969-
let other_address = ContractAddress::new(1, 0);
1970-
host.setup_query_contract_balance(other_address, Amount::from_micro_ccd(4000));
1971-
1972-
let entrypoint = OwnedEntrypointName::new_unchecked("test.method".to_string());
1973-
1974-
host.setup_mock_entrypoint(other_address, entrypoint.clone(), MockFn::returning_ok(()));
1975-
1976-
host.invoke_contract_raw(
1977-
&other_address,
1978-
Parameter::empty(),
1979-
entrypoint.as_entrypoint_name(),
1980-
Amount::from_micro_ccd(1000),
1981-
)
1982-
.expect("Invoke should succeed");
1983-
1984-
let other_new_balance = host.contract_balance(other_address).expect("Should succeed");
1985-
let self_new_balance = host.contract_balance(self_address).expect("Should succeed");
1986-
1987-
assert_eq!(other_new_balance, Amount::from_micro_ccd(5000));
1988-
assert_eq!(self_new_balance, Amount::from_micro_ccd(2000));
1989-
}
1990-
1991-
#[test]
1992-
// Perform a number of operations from Seek, Read, Write and HasStateApi
1993-
// classes on the TestStateApi structure and check that they behave as
1994-
// specified.
1995-
fn test_contract_state() {
1996-
let data = Rc::new(RefCell::new(vec![1; 100].into()));
1997-
let mut state = TestStateEntry::open(data, Vec::new(), 0);
1998-
assert_eq!(state.seek(SeekFrom::Start(100)), Ok(100), "Seeking to the end failed.");
1999-
assert_eq!(
2000-
state.seek(SeekFrom::Current(0)),
2001-
Ok(100),
2002-
"Seeking from current position with offset 0 failed."
2003-
);
2004-
assert!(
2005-
state.seek(SeekFrom::Current(1)).is_err(),
2006-
"Seeking from current position with offset 1 succeeded."
2007-
);
2008-
assert_eq!(state.cursor.offset, 100, "Cursor position changed on failed seek.");
2009-
assert_eq!(
2010-
state.seek(SeekFrom::Current(-1)),
2011-
Ok(99),
2012-
"Seeking from current position backwards with offset 1 failed."
2013-
);
2014-
assert!(state.seek(SeekFrom::Current(-100)).is_err(), "Seeking beyond beginning succeeds");
2015-
assert_eq!(state.seek(SeekFrom::Current(-99)), Ok(0), "Seeking to the beginning fails.");
2016-
assert_eq!(state.seek(SeekFrom::End(0)), Ok(100), "Seeking from end fails.");
2017-
assert!(
2018-
state.seek(SeekFrom::End(1)).is_err(),
2019-
"Seeking beyond the end succeeds but should fail."
2020-
);
2021-
assert_eq!(state.cursor.offset, 100, "Cursor position changed on failed seek.");
2022-
assert_eq!(
2023-
state.seek(SeekFrom::End(-20)),
2024-
Ok(80),
2025-
"Seeking from end leads to incorrect position."
2026-
);
2027-
assert_eq!(state.write(&[0; 21]), Ok(21), "Writing writes an incorrect amount of data.");
2028-
assert_eq!(state.cursor.offset, 101, "After writing the cursor is at the end.");
2029-
assert_eq!(state.write(&[0; 21]), Ok(21), "Writing again writes incorrect amount of data.");
2030-
let mut buf = [0; 30];
2031-
assert_eq!(state.read(&mut buf), Ok(0), "Reading from the end should read 0 bytes.");
2032-
assert_eq!(state.seek(SeekFrom::End(-20)), Ok(102));
2033-
assert_eq!(state.read(&mut buf), Ok(20), "Reading from offset 80 should read 20 bytes.");
2034-
assert_eq!(
2035-
&buf[0..20],
2036-
&state.cursor.data.borrow().data().expect("Entry was deleted")[80..100],
2037-
"Incorrect data was read."
2038-
);
2039-
assert_eq!(
2040-
state.cursor.offset, 122,
2041-
"After reading the offset is in the correct position."
2042-
);
2043-
assert!(state.reserve(222).is_ok(), "Could not increase state to 222.");
2044-
assert_eq!(state.write(&[2; 100]), Ok(100), "Should have written 100 bytes.");
2045-
assert_eq!(state.cursor.offset, 222, "After writing the offset should be 200.");
2046-
state.truncate(50).expect("Could not truncate state to 50.");
2047-
assert_eq!(state.cursor.offset, 50, "After truncation the state should be 50.");
2048-
assert_eq!(
2049-
state.write(&[1; 1000]),
2050-
Ok(1000),
2051-
"Writing at the end after truncation should succeed."
2052-
);
2053-
}
2054-
2055-
#[test]
2056-
fn test_contract_state_write() {
2057-
let data = Rc::new(RefCell::new(vec![0u8; 10].into()));
2058-
let mut state = TestStateEntry::open(data, Vec::new(), 0);
2059-
assert_eq!(state.write(&1u64.to_le_bytes()), Ok(8), "Incorrect number of bytes written.");
2060-
assert_eq!(
2061-
state.write(&2u64.to_le_bytes()),
2062-
Ok(8),
2063-
"State should be resized automatically."
2064-
);
2065-
assert_eq!(state.cursor.offset, 16, "Pos should be at the end.");
2066-
assert_eq!(
2067-
*state.cursor.data.as_ref().borrow().data().expect("Entry was deleted"),
2068-
vec![1, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0],
2069-
"Correct data was written."
2070-
);
2071-
}
2072-
}

0 commit comments

Comments
 (0)