Remove contract abi submodule (#139)

This commit is contained in:
bruno-valante 2024-07-22 17:32:51 +08:00 committed by GitHub
parent 116046366a
commit f0c3f2cfd0
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
20 changed files with 4406 additions and 17 deletions

48
.github/workflows/abi.yml vendored Normal file
View File

@ -0,0 +1,48 @@
name: abi-consistent-check
on:
push:
branches: [ "main"]
pull_request:
branches: [ "main" ]
jobs:
build-and-compare:
runs-on: ubuntu-latest
steps:
- name: Clone current repository
uses: actions/checkout@v3
- name: Get the Git revision from the current repository
id: get-rev
run: echo "rev=$(cat ./storage-contracts-abis/0g-storage-contracts-rev)" >> $GITHUB_OUTPUT
- name: Clone another repository
uses: actions/checkout@v3
with:
repository: '0glabs/0g-storage-contracts'
path: '0g-storage-contracts'
- name: Checkout specific revision
working-directory: ./0g-storage-contracts
run: |
git fetch --depth=1 origin ${{ steps.get-rev.outputs.rev }}
git checkout ${{ steps.get-rev.outputs.rev }}
- name: Set up Node.js
uses: actions/setup-node@v3
with:
node-version: '18.17'
cache: 'yarn'
cache-dependency-path: ./0g-storage-contracts
- name: Run yarn in the cloned repository
working-directory: ./0g-storage-contracts
run: |
yarn
yarn build
- name: Compare files
run: |
./scripts/check_abis.sh ./0g-storage-contracts/artifacts/

3
.gitmodules vendored
View File

@ -1,3 +0,0 @@
[submodule "0g-storage-contracts"]
path = 0g-storage-contracts
url = https://github.com/0glabs/0g-storage-contracts.git

@ -1 +0,0 @@
Subproject commit 25bc14a27441e8fb26e4d42d7c8c885f92d6c74a

View File

@ -3,16 +3,10 @@ use ethers::prelude::abigen;
// run `cargo doc -p contract-interface --open` to read struct definition
#[cfg(not(feature = "dev"))]
abigen!(
ZgsFlow,
"../../0g-storage-contracts/artifacts/contracts/dataFlow/Flow.sol/Flow.json"
);
abigen!(ZgsFlow, "../../storage-contracts-abis/Flow.json");
#[cfg(not(feature = "dev"))]
abigen!(
PoraMine,
"../../0g-storage-contracts/artifacts/contracts/miner/Mine.sol/PoraMine.json"
);
abigen!(PoraMine, "../../storage-contracts-abis/PoraMine.json");
#[cfg(feature = "dev")]
abigen!(

12
scripts/check_abis.sh Executable file
View File

@ -0,0 +1,12 @@
set -e
artifacts_path="$1"
check_abis() {
for contract_name in "$@"; do
diff $(./scripts/search_abi.sh "$artifacts_path" "$contract_name.json") "storage-contracts-abis/$contract_name.json"
done
}
check_abis DummyMarket DummyReward Flow PoraMine PoraMineTest FixedPrice OnePoolReward FixedPriceFlow

15
scripts/search_abi.sh Executable file
View File

@ -0,0 +1,15 @@
#!/bin/bash
directory="$1" # The directory to search in
filename="$2" # The filename to search for
# Find the file in the directory
found_files=$(find "$directory" -type f -name "$filename")
# Check if any files were found
if [ -z "$found_files" ]; then
echo "Error: No files named '$filename' found in directory '$directory'." >&2
exit 1
else
echo "$found_files"
fi

65
scripts/update_abis.sh Executable file
View File

@ -0,0 +1,65 @@
#!/bin/bash
set -e
default_path="../0g-storage-contracts"
path="${1:-$default_path}"
# Step 1: Check if the path is a valid Git directory with commits
if [ ! -d "$path/.git" ] || [ -z "$(git -C "$path" rev-parse HEAD 2> /dev/null)" ]; then
echo "Error: The specified path is not a valid Git repository with commits."
exit 1
fi
if [ ! -z "$(git -C "$path" status --porcelain)" ]; then
echo "Error: There are uncommitted changes in the contract repository."
exit 1
fi
# Step 2: Build the contracts
build_contracts() {
local target_path="$path"
local original_path=$(pwd) # Save the current directory
if cd "$target_path"; then
yarn
yarn build
cd "$original_path"
else
echo "Error: Failed to switch to directory $target_path."
exit 1
fi
}
build_contracts
# Step 3: Copy the file from a specified sub-path
copy_file() {
local source_path="$1"
local destination_path="$2"
# Check if the source file exists
if [ ! -f "$source_path" ]; then
echo "Error: The file $source_path does not exist."
exit 1
fi
# Copy the file to the destination
cp "$source_path" "$destination_path"
echo "File copied: $source_path -> $destination_path."
}
copy_abis() {
for contract_name in "$@"; do
copy_file $(./scripts/search_abi.sh "$path/artifacts" "$contract_name.json") "storage-contracts-abis/$contract_name.json"
done
}
copy_abis DummyMarket DummyReward Flow PoraMine PoraMineTest FixedPrice OnePoolReward FixedPriceFlow
# Step 4: Get the current Git revision and write it to a specified file
git_revision=$(git -C "$path" rev-parse HEAD)
revision_file="storage-contracts-abis/0g-storage-contracts-rev"
echo "$git_revision" > "$revision_file"
echo "Write git rev $git_revision to $revision_file."

View File

@ -0,0 +1 @@
6ec57942cba3068d3373bcb2c88f8fd51d2322b1

View File

@ -0,0 +1,34 @@
{
"_format": "hh-sol-artifact-1",
"contractName": "DummyMarket",
"sourceName": "contracts/test/DummyMarket.sol",
"abi": [
{
"inputs": [
{
"internalType": "uint256",
"name": "beforeLength",
"type": "uint256"
},
{
"internalType": "uint256",
"name": "uploadSectors",
"type": "uint256"
},
{
"internalType": "uint256",
"name": "paddingSectors",
"type": "uint256"
}
],
"name": "chargeFee",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
}
],
"bytecode": "0x6080604052348015600f57600080fd5b5060a08061001e6000396000f3fe6080604052348015600f57600080fd5b506004361060285760003560e01c8063da6eb36a14602d575b600080fd5b603d6038366004603f565b505050565b005b600080600060608486031215605357600080fd5b50508135936020830135935060409092013591905056fea264697066735822122054eb84b374e7eb5c57b284f82f977fe19500436ef4128d3e147969cefdd4cbcd64736f6c63430008100033",
"deployedBytecode": "0x6080604052348015600f57600080fd5b506004361060285760003560e01c8063da6eb36a14602d575b600080fd5b603d6038366004603f565b505050565b005b600080600060608486031215605357600080fd5b50508135936020830135935060409092013591905056fea264697066735822122054eb84b374e7eb5c57b284f82f977fe19500436ef4128d3e147969cefdd4cbcd64736f6c63430008100033",
"linkReferences": {},
"deployedLinkReferences": {}
}

View File

@ -0,0 +1,77 @@
{
"_format": "hh-sol-artifact-1",
"contractName": "DummyReward",
"sourceName": "contracts/test/DummyReward.sol",
"abi": [
{
"anonymous": false,
"inputs": [
{
"indexed": true,
"internalType": "uint256",
"name": "pricingIndex",
"type": "uint256"
},
{
"indexed": true,
"internalType": "address",
"name": "beneficiary",
"type": "address"
},
{
"indexed": false,
"internalType": "uint256",
"name": "amount",
"type": "uint256"
}
],
"name": "DistributeReward",
"type": "event"
},
{
"inputs": [
{
"internalType": "uint256",
"name": "pricingIndex",
"type": "uint256"
},
{
"internalType": "address payable",
"name": "beneficiary",
"type": "address"
},
{
"internalType": "bytes32",
"name": "minerId",
"type": "bytes32"
}
],
"name": "claimMineReward",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [
{
"internalType": "uint256",
"name": "beforeLength",
"type": "uint256"
},
{
"internalType": "uint256",
"name": "uploadSectors",
"type": "uint256"
}
],
"name": "fillReward",
"outputs": [],
"stateMutability": "payable",
"type": "function"
}
],
"bytecode": "0x608060405234801561001057600080fd5b5060f18061001f6000396000f3fe60806040526004361060265760003560e01c806359e9670014602b578063b7a3c04c14603c575b600080fd5b603a60363660046058565b5050565b005b348015604757600080fd5b50603a60533660046079565b505050565b60008060408385031215606a57600080fd5b50508035926020909101359150565b600080600060608486031215608d57600080fd5b8335925060208401356001600160a01b038116811460aa57600080fd5b92959294505050604091909101359056fea264697066735822122031a993c3def9ed899c5b5a53bab495d498047e1a8ce262b61e700511cfb9adf164736f6c63430008100033",
"deployedBytecode": "0x60806040526004361060265760003560e01c806359e9670014602b578063b7a3c04c14603c575b600080fd5b603a60363660046058565b5050565b005b348015604757600080fd5b50603a60533660046079565b505050565b60008060408385031215606a57600080fd5b50508035926020909101359150565b600080600060608486031215608d57600080fd5b8335925060208401356001600160a01b038116811460aa57600080fd5b92959294505050604091909101359056fea264697066735822122031a993c3def9ed899c5b5a53bab495d498047e1a8ce262b61e700511cfb9adf164736f6c63430008100033",
"linkReferences": {},
"deployedLinkReferences": {}
}

View File

@ -0,0 +1,113 @@
{
"_format": "hh-sol-artifact-1",
"contractName": "FixedPrice",
"sourceName": "contracts/market/FixedPrice.sol",
"abi": [
{
"inputs": [
{
"internalType": "uint256",
"name": "beforeLength",
"type": "uint256"
},
{
"internalType": "uint256",
"name": "uploadSectors",
"type": "uint256"
},
{
"internalType": "uint256",
"name": "paddingSectors",
"type": "uint256"
}
],
"name": "chargeFee",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [],
"name": "flow",
"outputs": [
{
"internalType": "address",
"name": "",
"type": "address"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [
{
"internalType": "uint256",
"name": "lifetimeMonthes",
"type": "uint256"
},
{
"internalType": "address",
"name": "flow_",
"type": "address"
},
{
"internalType": "address",
"name": "reward_",
"type": "address"
}
],
"name": "initialize",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [],
"name": "initialized",
"outputs": [
{
"internalType": "bool",
"name": "",
"type": "bool"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [],
"name": "pricePerSector",
"outputs": [
{
"internalType": "uint256",
"name": "",
"type": "uint256"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [],
"name": "reward",
"outputs": [
{
"internalType": "address",
"name": "",
"type": "address"
}
],
"stateMutability": "view",
"type": "function"
},
{
"stateMutability": "payable",
"type": "receive"
}
],
"bytecode": "0x608060405234801561001057600080fd5b5061057c806100206000396000f3fe6080604052600436106100595760003560e01c8063158ef93e14610065578063228cb73314610094578063343aad82146100cc57806361ec5082146100ec578063b4988fd014610110578063da6eb36a1461013257600080fd5b3661006057005b600080fd5b34801561007157600080fd5b5060005461007f9060ff1681565b60405190151581526020015b60405180910390f35b3480156100a057600080fd5b506035546100b4906001600160a01b031681565b6040516001600160a01b03909116815260200161008b565b3480156100d857600080fd5b506034546100b4906001600160a01b031681565b3480156100f857600080fd5b5061010260335481565b60405190815260200161008b565b34801561011c57600080fd5b5061013061012b36600461045b565b610152565b005b34801561013e57600080fd5b5061013061014d366004610497565b61024c565b60005460ff16156101b55760405162461bcd60e51b815260206004820152602260248201527f496e697469616c697a61626c653a20616c726561647920696e697469616c697a604482015261195960f21b60648201526084015b60405180910390fd5b6000805460ff19166001179055600c6101d0610400806104d9565b6101dc906104006104d9565b670de0b6b3a76400006101f2600a6101006104d9565b6101fc91906104d9565b61020691906104f8565b61021091906104f8565b61021a90846104d9565b603355603480546001600160a01b039384166001600160a01b0319918216179091556035805492909316911617905550565b6034546001600160a01b0316336001600160a01b0316146102af5760405162461bcd60e51b815260206004820152601f60248201527f53656e64657220646f6573206e6f742068617665207065726d697373696f6e0060448201526064016101ac565b60006102bb828461051a565b90506000836033546102cd91906104d9565b9050478111156103155760405162461bcd60e51b81526020600482015260136024820152724e6f7420656e6f75676820706169642066656560681b60448201526064016101ac565b60006103218247610533565b905060008361033086856104d9565b61033a91906104f8565b905060006103488285610533565b905085156103b7576035546040516259e96760e81b8152600481018a9052602481018890526001600160a01b03909116906359e967009084906044016000604051808303818588803b15801561039d57600080fd5b505af11580156103b1573d6000803e3d6000fd5b50505050505b6035546001600160a01b03166359e967006103d2838661051a565b6103dc898c61051a565b8a6040518463ffffffff1660e01b8152600401610403929190918252602082015260400190565b6000604051808303818588803b15801561041c57600080fd5b505af1158015610430573d6000803e3d6000fd5b50505050505050505050505050565b80356001600160a01b038116811461045657600080fd5b919050565b60008060006060848603121561047057600080fd5b833592506104806020850161043f565b915061048e6040850161043f565b90509250925092565b6000806000606084860312156104ac57600080fd5b505081359360208301359350604090920135919050565b634e487b7160e01b600052601160045260246000fd5b60008160001904831182151516156104f3576104f36104c3565b500290565b60008261051557634e487b7160e01b600052601260045260246000fd5b500490565b8082018082111561052d5761052d6104c3565b92915050565b8181038181111561052d5761052d6104c356fea26469706673582212207856f59ed7ef23f0c92ccfb266162bebd399dae56fd6a45b082c139f7e3b553064736f6c63430008100033",
"deployedBytecode": "0x6080604052600436106100595760003560e01c8063158ef93e14610065578063228cb73314610094578063343aad82146100cc57806361ec5082146100ec578063b4988fd014610110578063da6eb36a1461013257600080fd5b3661006057005b600080fd5b34801561007157600080fd5b5060005461007f9060ff1681565b60405190151581526020015b60405180910390f35b3480156100a057600080fd5b506035546100b4906001600160a01b031681565b6040516001600160a01b03909116815260200161008b565b3480156100d857600080fd5b506034546100b4906001600160a01b031681565b3480156100f857600080fd5b5061010260335481565b60405190815260200161008b565b34801561011c57600080fd5b5061013061012b36600461045b565b610152565b005b34801561013e57600080fd5b5061013061014d366004610497565b61024c565b60005460ff16156101b55760405162461bcd60e51b815260206004820152602260248201527f496e697469616c697a61626c653a20616c726561647920696e697469616c697a604482015261195960f21b60648201526084015b60405180910390fd5b6000805460ff19166001179055600c6101d0610400806104d9565b6101dc906104006104d9565b670de0b6b3a76400006101f2600a6101006104d9565b6101fc91906104d9565b61020691906104f8565b61021091906104f8565b61021a90846104d9565b603355603480546001600160a01b039384166001600160a01b0319918216179091556035805492909316911617905550565b6034546001600160a01b0316336001600160a01b0316146102af5760405162461bcd60e51b815260206004820152601f60248201527f53656e64657220646f6573206e6f742068617665207065726d697373696f6e0060448201526064016101ac565b60006102bb828461051a565b90506000836033546102cd91906104d9565b9050478111156103155760405162461bcd60e51b81526020600482015260136024820152724e6f7420656e6f75676820706169642066656560681b60448201526064016101ac565b60006103218247610533565b905060008361033086856104d9565b61033a91906104f8565b905060006103488285610533565b905085156103b7576035546040516259e96760e81b8152600481018a9052602481018890526001600160a01b03909116906359e967009084906044016000604051808303818588803b15801561039d57600080fd5b505af11580156103b1573d6000803e3d6000fd5b50505050505b6035546001600160a01b03166359e967006103d2838661051a565b6103dc898c61051a565b8a6040518463ffffffff1660e01b8152600401610403929190918252602082015260400190565b6000604051808303818588803b15801561041c57600080fd5b505af1158015610430573d6000803e3d6000fd5b50505050505050505050505050565b80356001600160a01b038116811461045657600080fd5b919050565b60008060006060848603121561047057600080fd5b833592506104806020850161043f565b915061048e6040850161043f565b90509250925092565b6000806000606084860312156104ac57600080fd5b505081359360208301359350604090920135919050565b634e487b7160e01b600052601160045260246000fd5b60008160001904831182151516156104f3576104f36104c3565b500290565b60008261051557634e487b7160e01b600052601260045260246000fd5b500490565b8082018082111561052d5761052d6104c3565b92915050565b8181038181111561052d5761052d6104c356fea26469706673582212207856f59ed7ef23f0c92ccfb266162bebd399dae56fd6a45b082c139f7e3b553064736f6c63430008100033",
"linkReferences": {},
"deployedLinkReferences": {}
}

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -0,0 +1,3 @@
This folder is maintained by the script `./scripts/update_abis.sh <0g-storage-contracts-path>`. Please do not modify it manually. The default value for `0g-storage-contracts-path` is `../0g-storage-contracts`.
When running the script, ensure that there are no uncommitted changes in the storage path and that `yarn` is already installed.

View File

@ -267,7 +267,7 @@ class BlockchainNode(TestNode):
def deploy_contract(name, args=None):
if args is None:
args = []
contract_interface = load_contract_metadata(base_path=self.contract_path, name=name)
contract_interface = load_contract_metadata(path=self.contract_path, name=name)
contract = w3.eth.contract(
abi=contract_interface["abi"],
bytecode=contract_interface["bytecode"],

View File

@ -1,11 +1,10 @@
from os.path import join
from pathlib import Path
import json
from web3 import Web3
def load_contract_metadata(base_path: str, name: str):
path = Path(join(base_path, "artifacts"))
def load_contract_metadata(path: str, name: str):
path = Path(path)
try:
found_file = next(path.rglob(f"{name}.json"))
return json.loads(open(found_file, "r").read())

View File

@ -256,7 +256,7 @@ class TestFramework:
dest="contract",
default=os.path.join(
__file_path__,
"../../0g-storage-contracts/",
"../../storage-contracts-abis/",
),
type=str,
)