Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[DO NO MERGE] test gas report #35

Open
wants to merge 9 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .github/scripts/contract-test-mapping.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"contracts/FeralFileAirdropV1.sol": ["test/feralfile_airdrop_v1.js"],
"contracts/FeralfileArtworkV3_3.sol": ["test/feralfile_exhibition_v3_3.js"],
"contracts/OwnerData.sol": ["test/owner_data.js"]
}
46 changes: 46 additions & 0 deletions .github/scripts/detect_and_test_changes.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#!/bin/bash

echo "Changed files: $CHANGED_FILES"

# Read the mapping file
declare -A MAPPING

# Use jq to iterate over each key-value pair in the JSON object.
while IFS= read -r line; do
contract=$(jq -r '.contract' <<< "$line")
IFS=$'\n' read -r -d '' -a tests < <(jq -r '.tests[]' <<< "$line" && printf '\0')

# Check if tests array is empty
if [ ${#tests[@]} -eq 0 ]; then
echo "Error: No tests found for contract $contract."
exit 1
fi

# Add each test to the mapping for the contract.
for test in "${tests[@]}"; do
MAPPING["$contract"]+="$test "
done
done < <(jq -c 'to_entries[] | {contract: .key, tests: .value}' .github/scripts/contract-test-mapping.json)


# Initialize a variable to hold test files to run
TEST_FILES=""

# Loop through changed files and append relevant test files
for FILE in $CHANGED_FILES; do
if [[ -n "${MAPPING[$FILE]}" ]]; then
TEST_FILES+="${MAPPING[$FILE]}"
fi
done

# Remove duplicate test files
TEST_FILES=$(echo "$TEST_FILES" | tr ' ' '\n' | sort -u | tr '\n' ' ')

# Run Truffle tests if there are any test files to run
if [ -n "$TEST_FILES" ]; then
echo "Running tests for changed contracts:"
echo $TEST_FILES
truffle test $TEST_FILES
else
echo "No contract changes detected."
fi
64 changes: 64 additions & 0 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
name: Solidity Test

on:
pull_request:
branches: [ main ]
paths:
- '**/*.sol'

jobs:
solidity-lint:
name: Test Solidity
runs-on: ubuntu-latest
steps:
- name: Check out code
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Set up Node.js
uses: actions/setup-node@v1
with:
node-version: '18'

- name: Get changed files
id: changed-files
uses: tj-actions/changed-files@v42

- name: Install dependencies
env:
CHANGED_FILES: ${{ steps.changed-files.outputs.all_changed_files }}
TARGET_BRANCH: ${{ github.base_ref }}
run: |
npm install
npm install -g truffle ganache
ganache -D -p 7545

- name: Write secret.json file
env:
MNEMONIC: ${{ secrets.MNEMONIC }}
MAINNET_ENDPOINT: ${{ secrets.MAINNET_ENDPOINT }}
GOERLI_ENDPOINT: ${{ secrets.GOERLI_ENDPOINT }}
BSCTEST_ENDPOINT: ${{ secrets.BSCTEST_ENDPOINT }}
BSC_ENDPOINT: ${{ secrets.BSC_ENDPOINT }}
ETHERSCAN_API: ${{ secrets.ETHERSCAN_API }}
BSC_API: ${{ secrets.BSC_API }}
run: |
cat <<EOF > .secret.json
{
"mnemonic": "${MNEMONIC}",
"mainnet_endpoint": "${MAINNET_ENDPOINT}",
"goerli_endpoint": "${GOERLI_ENDPOINT}",
"bsctest_endpoint": "${BSCTEST_ENDPOINT}",
"bsc_endpoint": "${BSC_ENDPOINT}",
"etherscan_api": "${ETHERSCAN_API}",
"bsc_api": "${BSC_API}"
}
EOF

- name: Test
env:
COINMARKETCAP_API_KEY: ${{ secrets.COINMARKETCAP_API_KEY }}
CHANGED_FILES: ${{ steps.changed-files.outputs.all_changed_files }}
TARGET_BRANCH: ${{ github.base_ref }}
run: .github/scripts/detect_and_test_changes.sh
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
"devDependencies": {
"@openzeppelin/test-helpers": "^0.5.16",
"coveralls": "^3.1.1",
"eth-gas-reporter": "^0.2.27",
"ganache-cli": "^6.12.2",
"solidity-coverage": "^0.7.22",
"truffle": "^5.9.2",
Expand Down
7 changes: 7 additions & 0 deletions truffle-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,13 @@ module.exports = {
// Set default mocha options here, use special reporters etc.
mocha: {
// timeout: 100000
reporter: 'eth-gas-reporter',
reporterOptions : {
currency: 'USD',
gasPriceApi: 'https://api.etherscan.io/api?module=proxy&action=eth_gasPrice',
token: 'ETH',
coinmarketcap: process.env.COINMARKETCAP_API_KEY
}
},

// Configure your compilers
Expand Down
Loading