Skip to content

Commit

Permalink
upd
Browse files Browse the repository at this point in the history
  • Loading branch information
maxknivets committed Oct 28, 2024
1 parent d6829c4 commit 14fd8f8
Show file tree
Hide file tree
Showing 8 changed files with 87 additions and 109 deletions.
14 changes: 11 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ This repository provides instructions on how to deploy your smart contract to th

## Example deploy address for Merged Precompiles 0x69420

[0x38dB0039707Bc60972D79eC8E752CA21aAfb0Ea2](https://explorer.wvm.dev/address/0x38dB0039707Bc60972D79eC8E752CA21aAfb0Ea2)
[0x9fb0F63B569f9FD8718Bbb2856a4b6F2458C2d70](https://explorer.wvm.dev/address/0x9fb0F63B569f9FD8718Bbb2856a4b6F2458C2d70)

## Prerequisites

Expand All @@ -22,10 +22,18 @@ forge create src/MergedPrecompiles0x69420.sol:MergedPrecompiles0x69420 --rpc-url
## Calling methods

```sh
cast call 0x38dB0039707Bc60972D79eC8E752CA21aAfb0Ea2 "read_from_arweave(string)" <ArweaveTXID> --rpc-url https://testnet-rpc.wvm.dev
cast call 0x9fb0F63B569f9FD8718Bbb2856a4b6F2458C2d70 "read_from_arweave(string)" <ArweaveTXID> --rpc-url https://testnet-rpc.wvm.dev

cast call 0x38dB0039707Bc60972D79eC8E752CA21aAfb0Ea2 "upload_to_arweave(string)" <dataString> --rpc-url https://testnet-rpc.wvm.dev
cast call 0x9fb0F63B569f9FD8718Bbb2856a4b6F2458C2d70 "upload_to_arweave(string)" <dataString> --rpc-url https://testnet-rpc.wvm.dev
```

Helper method example:

```sh
sh ./script/upload.sh
```
Feel free to substitute / change the contract address

## Notes

- The RPC URL `https://testnet-rpc.wvm.dev` is for the WVM testnet.
Expand Down
23 changes: 0 additions & 23 deletions script/deploy/ArweaveReader.sol

This file was deleted.

23 changes: 0 additions & 23 deletions script/deploy/ArweaveUploader.sol

This file was deleted.

23 changes: 0 additions & 23 deletions script/deploy/Precompile0x69420.sol

This file was deleted.

13 changes: 13 additions & 0 deletions script/upload.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/bin/bash
cast_output=$(cast call 0x9fb0F63B569f9FD8718Bbb2856a4b6F2458C2d70 "upload_to_arweave(string)" "hello world!" --rpc-url https://testnet-rpc.wvm.dev)

data_hex=$(echo "$cast_output" | cut -c 129-214)

# Decode the hex data to get the Arweave transaction hash
tx_hash=$(echo "$data_hex" | xxd -r -p)

# Generate the viewblock.io URL using the extracted transaction hash
viewblock_url="https://viewblock.io/arweave/tx/$tx_hash"

# Output the URL
echo "$viewblock_url"
8 changes: 4 additions & 4 deletions src/MergedPrecompiles0x69420.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,18 @@ pragma solidity ^0.8.0;
// THIS CODE IS LIT 🌿🔥

contract MergedPrecompiles0x69420 {
function read_from_arweave(string memory txIdOrGatewayAndTxId) public view returns (bytes memory) {
function read_from_arweave(string memory txIdOrGatewayAndTxId) public view returns (string memory) {
bytes memory data = abi.encodePacked(txIdOrGatewayAndTxId);
(bool success, bytes memory result) = address(0x18).staticcall(data);
require(success, "ArweaveReader: read operation failed");
return result;
return string(result);
}

function upload_to_arweave(string memory dataString) public view returns (bytes memory) {
function upload_to_arweave(string memory dataString) public returns (string memory) {
bytes memory data = abi.encodePacked(dataString);
(bool success, bytes memory result) = address(0x17).staticcall(data);
require(success, "ArweaveUploader: upload operation failed");
return result;
return string(result);
}

}
Expand Down
59 changes: 59 additions & 0 deletions test/MergedPrecompiles0x69420.t.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

import "forge-std/Test.sol";
import "../src/MergedPrecompiles0x69420.sol";

contract MergedPrecompiles0x69420Test is Test {
MergedPrecompiles0x69420 public precompile;

// Events we want to test
event UploadAttempted(string data, bool success);
event UploadError(string reason);
event ReadAttempted(string txId, bool success);
event ReadError(string reason);

function setUp() public {
precompile = new MergedPrecompiles0x69420();
}

function testReadFromArweave() public {
// Mock the precompile call
vm.mockCall(
address(0x18),
abi.encodePacked("test_tx_id"),
abi.encodePacked("mocked_result")
);

bytes memory result = precompile.read_from_arweave("test_tx_id");
assertEq(result, "mocked_result");
}

function testReadFromArweaveFailure() public {
// Mock a failed precompile call
vm.mockCallRevert(
address(0x18),
abi.encodePacked("invalid_tx_id"),
"Read operation failed"
);

vm.expectRevert("ArweaveReader: read operation failed");
precompile.read_from_arweave("invalid_tx_id");
}

function testUploadToArweave() public {
// Mock successful upload
vm.mockCall(
address(0x17),
abi.encodePacked("test_data"),
abi.encodePacked("mocked_tx_id")
);

// Expect the UploadAttempted event to be emitted
vm.expectEmit(true, true, true, true);
emit UploadAttempted("test_data", true);

bytes memory result = precompile.upload_to_arweave("test_data");
assertEq(result, "mocked_tx_id");
}
}
33 changes: 0 additions & 33 deletions test/Precompile0x69420.t.sol

This file was deleted.

0 comments on commit 14fd8f8

Please sign in to comment.