mapping_deletion.sol 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. contract savedTest {
  2. uint b;
  3. constructor(uint d) {
  4. b = d;
  5. }
  6. function increment(uint f) public {
  7. b += f;
  8. }
  9. }
  10. contract DeleteTest {
  11. struct data_struct {
  12. address addr1;
  13. address addr2;
  14. }
  15. mapping(uint => data_struct) example;
  16. mapping(uint => address) example2;
  17. function addData(address pid) public {
  18. data_struct dt = data_struct({addr1: address(this), addr2: tx.accounts.dataAccount.key});
  19. uint id = 1;
  20. example[id] = dt;
  21. savedTest.new{program_id: pid}(4);
  22. example2[id] = pid;
  23. }
  24. function deltest() external {
  25. uint id = 1;
  26. delete example[id];
  27. //delete example2[id];
  28. }
  29. function get() public view returns (data_struct calldata) {
  30. uint id = 1;
  31. return example[id];
  32. }
  33. }
  34. // ---- Expect: diagnostics ----
  35. // error: 25:9-42: accounts are required for calling a contract. You can either provide the accounts with the {accounts: ...} call argument or change this function's visibility to external