This repository has been archived by the owner on Feb 14, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 17
/
payable.rs
119 lines (97 loc) · 3.16 KB
/
payable.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
#![allow(dead_code)]
use pwasm_abi_derive::eth_abi;
use pwasm_abi::eth::EndpointInterface;
use pwasm_test::{ext_reset};
const PAYLOAD_BAZ: &[u8] = &[
0xcd, 0xcd, 0x77, 0xc0,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x45,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
];
const PAYLOAD_BOO: &[u8] = &[
0x5d, 0xda, 0xb4, 0xd4,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x45,
];
#[eth_abi(NonPayableEndpoint)]
pub trait NonPayableContract {
fn constructor(&mut self);
fn baz(&mut self, _p1: u32, _p2: bool);
fn boo(&mut self, _arg: u32) -> u32;
}
struct NonPayableContractInstance;
impl NonPayableContract for NonPayableContractInstance {
fn constructor(&mut self) {}
fn baz(&mut self, _p1: u32, _p2: bool) {}
fn boo(&mut self, _arg: u32) -> u32 { 0 }
}
#[test]
#[should_panic]
fn non_payable_constructor_value() {
ext_reset(|e| e.value(1.into()));
NonPayableEndpoint::new(NonPayableContractInstance).dispatch_ctor(&[]);
}
#[test]
#[should_panic]
fn non_payable_value() {
ext_reset(|e| e.value(1.into()));
NonPayableEndpoint::new(NonPayableContractInstance).dispatch(PAYLOAD_BAZ);
}
#[test]
#[should_panic]
fn non_payable_with_ret_value() {
ext_reset(|e| e.value(1.into()));
NonPayableEndpoint::new(NonPayableContractInstance).dispatch(PAYLOAD_BOO);
}
#[test]
fn non_payable_constructor_no_value() {
NonPayableEndpoint::new(NonPayableContractInstance).dispatch_ctor(&[]);
}
#[test]
fn non_payable_no_value() {
NonPayableEndpoint::new(NonPayableContractInstance).dispatch(PAYLOAD_BAZ);
}
#[test]
fn non_payable_no_value_ret() {
NonPayableEndpoint::new(NonPayableContractInstance).dispatch(PAYLOAD_BOO);
}
#[eth_abi(PayableEndpoint)]
pub trait PayableContract {
#[payable]
fn constructor(&mut self);
#[payable]
fn baz(&mut self, _p1: u32, _p2: bool);
#[payable]
fn boo(&mut self, _arg: u32) -> u32;
}
struct PayableContractInstance;
impl PayableContract for PayableContractInstance {
fn constructor(&mut self) {}
fn baz(&mut self, _p1: u32, _p2: bool) {}
fn boo(&mut self, _arg: u32) -> u32 { 0 }
}
#[test]
fn payable_constructor() {
ext_reset(|e| e.value(1.into()));
PayableEndpoint::new(PayableContractInstance).dispatch_ctor(&[]);
}
#[test]
fn payable_method() {
ext_reset(|e| e.value(1.into()));
PayableEndpoint::new(PayableContractInstance).dispatch(PAYLOAD_BAZ);
}
#[test]
fn payable_method_ret() {
ext_reset(|e| e.value(1.into()));
PayableEndpoint::new(PayableContractInstance).dispatch(PAYLOAD_BOO);
}
#[test]
fn payable_constructor_no_value() {
PayableEndpoint::new(PayableContractInstance).dispatch_ctor(&[]);
}
#[test]
fn payable_method_no_value() {
PayableEndpoint::new(PayableContractInstance).dispatch(PAYLOAD_BAZ);
}
#[test]
fn payable_method_ret_no_value() {
PayableEndpoint::new(PayableContractInstance).dispatch(PAYLOAD_BOO);
}