Skip to content

Commit

Permalink
Add test for unstable syscall
Browse files Browse the repository at this point in the history
  • Loading branch information
athei committed Dec 4, 2024
1 parent c7bfd01 commit 69ec9e5
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 0 deletions.
44 changes: 44 additions & 0 deletions substrate/frame/revive/fixtures/contracts/unstable_interface.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
// This file is part of Substrate.

// Copyright (C) Parity Technologies (UK) Ltd.
// SPDX-License-Identifier: Apache-2.0

// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#![no_std]
#![no_main]

extern crate common;

#[polkavm_derive::polkavm_import]
extern "C" {
pub fn set_code_hash();
}

// Export that is never called. We can put code here that should be in the binary
// but is never supposed to be run.
#[no_mangle]
#[polkavm_derive::polkavm_export]
pub extern "C" fn call_never() {
// make sure it is not optimized away
unsafe {
set_code_hash();
}
}

#[no_mangle]
#[polkavm_derive::polkavm_export]
pub extern "C" fn deploy() {}

#[no_mangle]
#[polkavm_derive::polkavm_export]
pub extern "C" fn call() {}
18 changes: 18 additions & 0 deletions substrate/frame/revive/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4680,3 +4680,21 @@ fn unknown_syscall_rejected() {
)
});
}

#[test]
fn unstable_interface_rejected() {
let (code, _) = compile_module("unstable_interface").unwrap();

ExtBuilder::default().existential_deposit(100).build().execute_with(|| {
<Test as Config>::Currency::set_balance(&ALICE, 1_000_000);

Test::set_unstable_interface(false);
assert_err!(
builder::bare_instantiate(Code::Upload(code.clone())).build().result,
<Error<Test>>::CodeRejected,
);

Test::set_unstable_interface(true);
assert_ok!(builder::bare_instantiate(Code::Upload(code)).build().result);
});
}

0 comments on commit 69ec9e5

Please sign in to comment.