-
Notifications
You must be signed in to change notification settings - Fork 721
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[pallet-revive] implement tx origin API #6105
Changes from 7 commits
09e8c47
5563391
32e6095
a8c01be
0dd2c17
f472086
f59d4e4
2a186f7
584a59b
1c27bdf
efa3f06
3f06067
06129c7
8c6a070
2af28af
6a08871
9640c27
c4dc08a
2608b90
3b1e024
f999fd8
3b8c0bd
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
title: '[pallet-revive] implement tx origin API' | ||
|
||
doc: | ||
- audience: | ||
- Runtime Dev | ||
description: Implement a syscall to retreive the transaction origin. | ||
|
||
crates: | ||
- name: pallet-revive | ||
bump: minor | ||
- name: pallet-revive-uapi | ||
bump: minor | ||
- name: pallet-revive-fixtures | ||
bump: patch |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
// 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. | ||
|
||
//! Tests that the `origin` syscall works. | ||
|
||
#![no_std] | ||
#![no_main] | ||
|
||
use common::input; | ||
use uapi::{HostFn, HostFnImpl as api}; | ||
|
||
#[no_mangle] | ||
#[polkavm_derive::polkavm_export] | ||
pub extern "C" fn deploy() { | ||
call() | ||
} | ||
|
||
#[no_mangle] | ||
#[polkavm_derive::polkavm_export] | ||
pub extern "C" fn call() { | ||
input!(expected: &[u8; 20],); | ||
|
||
let mut received = [0; 20]; | ||
api::origin(&mut received); | ||
|
||
assert_eq!(expected, &received); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4442,4 +4442,18 @@ mod run_tests { | |
); | ||
}); | ||
} | ||
|
||
#[test] | ||
fn origin_api_works() { | ||
let (code, _) = compile_module("origin").unwrap(); | ||
|
||
ExtBuilder::default().existential_deposit(100).build().execute_with(|| { | ||
let _ = <Test as Config>::Currency::set_balance(&ALICE, 1_000_000); | ||
|
||
// Create fixture: Constructor tests the origin to be equal the input data | ||
builder::bare_instantiate(Code::Upload(code)) | ||
.data(ALICE_ADDR.0.to_vec()) | ||
.build_and_unwrap_contract(); | ||
}); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Caller = Origin in this case. I think it should also test where this is not the case. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Deemed it unnecessary as this is already covered by the unit tests. Changed the fixture to go through both paths. |
||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not return a reference?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Copy paste from
fn caller
which returns a value too. But I don't see why it can't be a reference. Changed it