Skip to content

Commit

Permalink
test: use WASM for backwards-compatibility tests (#9173)
Browse files Browse the repository at this point in the history
`base_test_contract_rs.wasm` is a WASM used in our tests that is
supposed to be compatible with the oldest version.
That currently requires rustc < 1.70 or some hacks to
use unstable cargo features. (`-Zbuild-std`)

The easiest way forward is to check in a WASM built with the correct
settings instead or relying on the nearcore toolchain version.

This is a pre-requisite to land the 1.70 toolchain upgrade. (#9140)
  • Loading branch information
jakmeier authored Jun 12, 2023
1 parent 0d6644f commit 863f712
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 1 deletion.
1 change: 0 additions & 1 deletion runtime/near-test-contracts/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ fn main() {

fn try_main() -> Result<(), Error> {
build_contract("./test-contract-rs", &["--features", "latest_protocol"], "test_contract_rs")?;
build_contract("./test-contract-rs", &[], "base_test_contract_rs")?;
build_contract(
"./test-contract-rs",
&["--features", "latest_protocol,nightly"],
Expand Down
Binary file not shown.
9 changes: 9 additions & 0 deletions runtime/near-test-contracts/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,15 @@ pub fn rs_contract() -> &'static [u8] {
/// This is useful for tests that use a specific protocol version rather then
/// just the latest one. In particular, protocol upgrade tests should use this
/// function rather than [`rs_contract`].
///
/// Note: Unlike other contracts, this is not automatically build from source
/// but instead a WASM in checked into source control. To serve the oldest
/// protocol version, we need a WASM that does not contain instructions beyond
/// the WASM MVP. Rustc >=1.70 uses LLVM with the [sign
/// extension](https://github.com/WebAssembly/spec/blob/main/proposals/sign-extension-ops/Overview.md)
/// enabled. So we have to build it with Rustc <= 1.69. If we need to update the
/// contracts content, we can build it manually with an older compiler and check
/// in the new WASM.
pub fn base_rs_contract() -> &'static [u8] {
static CONTRACT: OnceCell<Vec<u8>> = OnceCell::new();
CONTRACT.get_or_init(|| read_contract("base_test_contract_rs.wasm")).as_slice()
Expand Down

0 comments on commit 863f712

Please sign in to comment.