modifiers.rs 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. // SPDX-License-Identifier: Apache-2.0
  2. use crate::{build_solidity, BorshToken};
  3. use num_bigint::BigInt;
  4. #[test]
  5. fn returns_and_phis_needed() {
  6. let mut vm = build_solidity(
  7. r#"
  8. contract c {
  9. int foo;
  10. bool bar;
  11. function func(bool cond) external mod(cond) returns (int, bool) {
  12. return (foo, bar);
  13. }
  14. modifier mod(bool cond) {
  15. bar = cond;
  16. if (cond) {
  17. foo = 12;
  18. _;
  19. } else {
  20. foo = 40;
  21. _;
  22. }
  23. }
  24. }"#,
  25. );
  26. vm.constructor("c", &[]);
  27. let returns = vm.function("func", &[BorshToken::Bool(false)]);
  28. assert_eq!(
  29. returns,
  30. vec![
  31. BorshToken::Int {
  32. width: 256,
  33. value: BigInt::from(40u8),
  34. },
  35. BorshToken::Bool(false)
  36. ]
  37. );
  38. let returns = vm.function("func", &[BorshToken::Bool(true)]);
  39. assert_eq!(
  40. returns,
  41. vec![
  42. BorshToken::Int {
  43. width: 256,
  44. value: BigInt::from(12u8)
  45. },
  46. BorshToken::Bool(true)
  47. ]
  48. );
  49. }