storage.rs 793 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. // SPDX-License-Identifier: Apache-2.0
  2. use crate::build_solidity;
  3. use parity_scale_codec::{Decode, Encode};
  4. #[test]
  5. fn storage_load_on_return() {
  6. #[derive(Debug, PartialEq, Eq, Encode, Decode)]
  7. struct SStruct {
  8. f1: i32,
  9. }
  10. let mut runtime = build_solidity(
  11. r##"
  12. contract foo {
  13. struct S { int32 f1; }
  14. S[] arr;
  15. function g() private returns (S storage, S storage) {
  16. return (arr[0], arr[1]);
  17. }
  18. function f() public returns (S, S) {
  19. S[] storage ptrArr = arr;
  20. ptrArr.push(S({f1: 1}));
  21. ptrArr.push(S({f1: 2}));
  22. return g();
  23. }
  24. }
  25. "##,
  26. );
  27. runtime.function("f", Vec::new());
  28. assert_eq!(
  29. runtime.vm.output,
  30. [SStruct { f1: 1 }, SStruct { f1: 2 }].encode(),
  31. );
  32. }