Skip to content

Commit f455935

Browse files
committed
Disallow refund methods
1 parent 619563e commit f455935

File tree

2 files changed

+116
-2
lines changed

2 files changed

+116
-2
lines changed

crates/radix-engine-toolkit/src/instruction_visitor/visitors/transaction_type/general_transaction_visitor.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -828,8 +828,6 @@ fn construct_fn_rules(entity_type: EntityType) -> FnRules {
828828
/* All deposit methods */
829829
ACCOUNT_DEPOSIT_IDENT,
830830
ACCOUNT_DEPOSIT_BATCH_IDENT,
831-
ACCOUNT_TRY_DEPOSIT_OR_REFUND_IDENT,
832-
ACCOUNT_TRY_DEPOSIT_BATCH_OR_REFUND_IDENT,
833831
ACCOUNT_TRY_DEPOSIT_OR_ABORT_IDENT,
834832
ACCOUNT_TRY_DEPOSIT_BATCH_OR_ABORT_IDENT,
835833
/* All proof creation methods */
@@ -851,6 +849,9 @@ fn construct_fn_rules(entity_type: EntityType) -> FnRules {
851849
ACCOUNT_REMOVE_RESOURCE_PREFERENCE_IDENT,
852850
ACCOUNT_ADD_AUTHORIZED_DEPOSITOR,
853851
ACCOUNT_REMOVE_AUTHORIZED_DEPOSITOR,
852+
/* Deposit or Refund */
853+
ACCOUNT_TRY_DEPOSIT_OR_REFUND_IDENT,
854+
ACCOUNT_TRY_DEPOSIT_BATCH_OR_REFUND_IDENT,
854855
/* All fee locking methods */
855856
ACCOUNT_LOCK_FEE_IDENT,
856857
ACCOUNT_LOCK_CONTINGENT_FEE_IDENT,

crates/radix-engine-toolkit/tests/general_transaction_visitor.rs

Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,3 +135,116 @@ fn account_add_authorized_depositor_method_is_disallowed_in_general_transaction(
135135
// Assert
136136
assert!(visitor.output().is_none())
137137
}
138+
139+
#[test]
140+
fn deposit_or_abort_is_valid_for_general_transaction_type() {
141+
// Arrange
142+
let mut test_runner = TestRunnerBuilder::new().without_trace().build();
143+
let (public_key1, _, account1) = test_runner.new_account(true);
144+
let (public_key2, _, account2) = test_runner.new_account(true);
145+
146+
let manifest = ManifestBuilder::new()
147+
.withdraw_from_account(account1, XRD, dec!("10"))
148+
.take_from_worktop(XRD, dec!("10"), "bucket")
149+
.try_deposit_or_abort(account2, None, "bucket")
150+
.build();
151+
let receipt = test_runner.preview_manifest(
152+
manifest.clone(),
153+
vec![public_key1.into(), public_key2.into()],
154+
0,
155+
PreviewFlags {
156+
use_free_credit: true,
157+
assume_all_signature_proofs: true,
158+
skip_epoch_check: true,
159+
},
160+
);
161+
receipt.expect_commit_success();
162+
163+
// Act
164+
let mut visitor = GeneralTransactionTypeVisitor::new(
165+
receipt
166+
.expect_commit_success()
167+
.execution_trace
168+
.as_ref()
169+
.unwrap(),
170+
);
171+
traverse(&manifest.instructions, &mut [&mut visitor]).unwrap();
172+
173+
// Assert
174+
assert!(visitor.output().is_some());
175+
}
176+
177+
#[test]
178+
fn deposit_or_refund_invalidates_general_transaction_type() {
179+
// Arrange
180+
let mut test_runner = TestRunnerBuilder::new().without_trace().build();
181+
let (public_key1, _, account1) = test_runner.new_account(true);
182+
let (public_key2, _, account2) = test_runner.new_account(true);
183+
184+
let manifest = ManifestBuilder::new()
185+
.withdraw_from_account(account1, XRD, dec!("10"))
186+
.take_from_worktop(XRD, dec!("10"), "bucket")
187+
.try_deposit_or_refund(account2, None, "bucket")
188+
.build();
189+
let receipt = test_runner.preview_manifest(
190+
manifest.clone(),
191+
vec![public_key1.into(), public_key2.into()],
192+
0,
193+
PreviewFlags {
194+
use_free_credit: true,
195+
assume_all_signature_proofs: true,
196+
skip_epoch_check: true,
197+
},
198+
);
199+
receipt.expect_commit_success();
200+
201+
// Act
202+
let mut visitor = GeneralTransactionTypeVisitor::new(
203+
receipt
204+
.expect_commit_success()
205+
.execution_trace
206+
.as_ref()
207+
.unwrap(),
208+
);
209+
traverse(&manifest.instructions, &mut [&mut visitor]).unwrap();
210+
211+
// Assert
212+
assert!(visitor.output().is_none());
213+
}
214+
215+
#[test]
216+
fn deposit_batch_or_refund_invalidates_general_transaction_type() {
217+
// Arrange
218+
let mut test_runner = TestRunnerBuilder::new().without_trace().build();
219+
let (public_key1, _, account1) = test_runner.new_account(true);
220+
let (public_key2, _, account2) = test_runner.new_account(true);
221+
222+
let manifest = ManifestBuilder::new()
223+
.withdraw_from_account(account1, XRD, dec!("10"))
224+
.try_deposit_entire_worktop_or_refund(account2, None)
225+
.build();
226+
let receipt = test_runner.preview_manifest(
227+
manifest.clone(),
228+
vec![public_key1.into(), public_key2.into()],
229+
0,
230+
PreviewFlags {
231+
use_free_credit: true,
232+
assume_all_signature_proofs: true,
233+
skip_epoch_check: true,
234+
},
235+
);
236+
receipt.expect_commit_success();
237+
238+
// Act
239+
let mut visitor = GeneralTransactionTypeVisitor::new(
240+
receipt
241+
.expect_commit_success()
242+
.execution_trace
243+
.as_ref()
244+
.unwrap(),
245+
);
246+
traverse(&manifest.instructions, &mut [&mut visitor]).unwrap();
247+
248+
// Assert
249+
assert!(visitor.output().is_none());
250+
}

0 commit comments

Comments
 (0)