constant.rs 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. // SPDX-License-Identifier: Apache-2.0
  2. use crate::{build_solidity, BorshToken};
  3. use num_bigint::BigInt;
  4. #[test]
  5. fn constant() {
  6. let mut vm = build_solidity(
  7. r#"
  8. library Library {
  9. uint256 internal constant STATIC = 42;
  10. }
  11. contract foo {
  12. function f() public returns (uint) {
  13. uint a = Library.STATIC;
  14. return a;
  15. }
  16. }
  17. "#,
  18. );
  19. let data_account = vm.initialize_data_account();
  20. vm.function("new")
  21. .accounts(vec![("dataAccount", data_account)])
  22. .call();
  23. let returns = vm.function("f").call().unwrap();
  24. assert_eq!(
  25. returns,
  26. BorshToken::Uint {
  27. width: 256,
  28. value: BigInt::from(42u8)
  29. }
  30. );
  31. let mut vm = build_solidity(
  32. r#"
  33. contract C {
  34. uint256 public constant STATIC = 42;
  35. }
  36. contract foo {
  37. function f() public returns (uint) {
  38. uint a = C.STATIC;
  39. return a;
  40. }
  41. }
  42. "#,
  43. );
  44. let data_account = vm.initialize_data_account();
  45. vm.function("new")
  46. .accounts(vec![("dataAccount", data_account)])
  47. .call();
  48. let returns = vm.function("f").call().unwrap();
  49. assert_eq!(
  50. returns,
  51. BorshToken::Uint {
  52. width: 256,
  53. value: BigInt::from(42u8)
  54. }
  55. );
  56. }