-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* fix build * fix * fix scripts * fix scripts * remove foundry-devops dependency * add Makefile * add help to Makefile * make help the default target in Makefile * refactor * make tests pass --------- Co-authored-by: Viacheslav Zhygulin <[email protected]> Co-authored-by: Viacheslav Zhygulin <[email protected]>
- Loading branch information
1 parent
e50849e
commit 1bcf1b4
Showing
19 changed files
with
328 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,4 +13,7 @@ docs/ | |
# Dotenv file | ||
.env | ||
|
||
__pycache__ | ||
__pycache__ | ||
|
||
.vscode | ||
temp/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,9 @@ | ||
[submodule "lib/forge-std"] | ||
path = lib/forge-std | ||
url = https://github.com/foundry-rs/forge-std | ||
[submodule "lib/foundry-devops"] | ||
path = lib/foundry-devops | ||
url = https://github.com/Cyfrin/foundry-devops | ||
[submodule "lib/elliptic-curve-solidity"] | ||
path = lib/elliptic-curve-solidity | ||
url = https://github.com/witnet/elliptic-curve-solidity | ||
[submodule "lib/openzeppelin-contracts"] | ||
path = lib/openzeppelin-contracts | ||
url = https://github.com/OpenZeppelin/openzeppelin-contracts |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
# https://stackoverflow.com/questions/5377297/how-to-manually-call-another-target-from-a-make-target | ||
# Determine this makefile's path. | ||
# Be sure to place this BEFORE `include` directives, if any. | ||
THIS_FILE := $(lastword $(MAKEFILE_LIST)) | ||
|
||
# Keys are generated determistically in anvil so they are the same during different runs | ||
# as long the seed is the same. | ||
# Some keys and addresses are copy-pasted in file `env-anvil`. | ||
# https://unix.stackexchange.com/questions/235223/makefile-include-env-file | ||
include env-anvil | ||
export $(shell sed 's/=.*//' env-anvil) | ||
|
||
RED := $(shell tput -Txterm setaf 1) | ||
GREEN := $(shell tput -Txterm setaf 2) | ||
YELLOW := $(shell tput -Txterm setaf 3) | ||
WHITE := $(shell tput -Txterm setaf 7) | ||
CYAN := $(shell tput -Txterm setaf 6) | ||
RESET := $(shell tput -Txterm sgr0) | ||
|
||
.PHONY: default | ||
default: help | ||
|
||
## Build: | ||
.PHONY: build | ||
build: ## Build library. | ||
forge build | ||
|
||
.PHONY: clean | ||
clean: ## Clean tempory files. Sometimes forge incorrectly updates its cache. So if there are some strange errors run `make clean`. | ||
rm -rf cache | ||
rm -rf out | ||
|
||
## Work with local anvil: | ||
.PHONY: start-anvil | ||
start-anvil: ## Starts anvil with default parameters. | ||
anvil | ||
|
||
.PHONY: deploy-on-anvil | ||
deploy-on-anvil: ## Deploy BTCDepositAddressDeriver smart contract on local anvil blockchain. | ||
mkdir -p temp | ||
forge script \ | ||
script/Deploy.s.sol:Deploy \ | ||
--fork-url ${ANVIL_RPC_URL} \ | ||
--broadcast \ | ||
--private-key=${ETH_PRIVKEY_0_ANVIL} | ||
|
||
.PHONY: set-sample-seed | ||
set-sample-seed: ## Set sample seed on previously deployed BTCDepositAddressDeriver. | ||
BTC_ADDR1=tb1p5z8wl5tu7m0d79vzqqsl9gu0x4fkjug857fusx4fl4kfgwh5j25spa7245 \ | ||
BTC_ADDR2=tb1pfusykjdt46ktwq03d20uqqf94uh9487344wr3q5v9szzsxnjdfks9apcjz \ | ||
BTC_NETWORK=0 \ | ||
forge script \ | ||
-vvv \ | ||
script/SetSeed.s.sol:SetSeed \ | ||
--fork-url ${ANVIL_RPC_URL} \ | ||
--broadcast \ | ||
--private-key=${ETH_PRIVKEY_0_ANVIL} | ||
|
||
.PHONY: get-sample-btc-address | ||
get-sample-btc-address: ## Calculates bitcoin address from the sample ethereum address using previously deployed BTCDepositAddressDeriver. | ||
ETH_ADDR=${ETH_ADDR_1_ANVIL} \ | ||
BTC_ADDR_FILE=./temp/btc.address \ | ||
forge script -vvv \ | ||
script/GetBtcAddr.s.sol:GetBtcAddr \ | ||
--fork-url ${ANVIL_RPC_URL} | ||
|
||
## Test: | ||
.PHONY: test | ||
test: ## Run unit tests. | ||
forge test | ||
|
||
.PHONY: test-sample-flow | ||
test-sample-flow: ## Run integration test that deploys smart contract, set seed and calculate sample bitcoin address. It requires anvil to be running. | ||
@$(MAKE) -f $(THIS_FILE) deploy-on-anvil | ||
@$(MAKE) -f $(THIS_FILE) set-sample-seed | ||
@$(MAKE) -f $(THIS_FILE) get-sample-btc-address | ||
if [ `cat ./temp/btc.address` = "tb1pxt2g6ltjvle3wupwzlg9yuqw5rsswvvjg20eegq46l3yx6ekc2psh78607" ]; \ | ||
then \ | ||
echo "${GREEN}OK${RESET}"; \ | ||
exit 0; \ | ||
else \ | ||
echo "${RED}ERROR${RESET}"; \ | ||
exit 1; \ | ||
fi | ||
|
||
.PHONY: test-all | ||
test-all: test test-sample-flow ## Run unit and integrations tests. It requires anvil to be running. | ||
|
||
## Help: | ||
.PHONY: help | ||
help: ## Show this help | ||
@echo '' | ||
@echo 'Usage:' | ||
@echo ' ${YELLOW}make${RESET} ${GREEN}<target>${RESET}' | ||
@echo '' | ||
@echo 'Targets:' | ||
@awk 'BEGIN {FS = ":.*?## "} { \ | ||
if (/^[a-zA-Z0-9_-]+:.*?##.*$$/) {printf " ${YELLOW}%-25s${GREEN}%s${RESET}\n", $$1, $$2} \ | ||
else if (/^## .*$$/) {printf " ${CYAN}%s${RESET}\n", substr($$1,4)} \ | ||
}' $(MAKEFILE_LIST) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,11 @@ | ||
[profile.default] | ||
solc = "0.8.25" | ||
src = "src" | ||
out = "out" | ||
libs = ["lib"] | ||
fs_permissions = [{ access = "read", path = "./broadcast" }] | ||
fs_permissions = [ | ||
{ access = "read", path = "./broadcast" }, | ||
{ access = "read-write", path = "./temp" } | ||
] | ||
|
||
# See more config options https://github.com/foundry-rs/foundry/blob/master/crates/config/README.md#all-options |
Submodule forge-std
updated
12 files
+6 −12 | .github/workflows/ci.yml | |
+3 −1 | .github/workflows/sync.yml | |
+2 −2 | foundry.toml | |
+1 −1 | package.json | |
+1 −1 | src/StdAssertions.sol | |
+7 −7 | src/StdChains.sol | |
+9 −3 | src/StdInvariant.sol | |
+1 −1 | src/StdUtils.sol | |
+119 −6 | src/Vm.sol | |
+7 −7 | test/StdChains.t.sol | |
+1 −1 | test/StdCheats.t.sol | |
+2 −2 | test/Vm.t.sol |
Submodule foundry-devops
deleted from
5415fa
Submodule openzeppelin-contracts
added at
dbb610
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
ds-test/=forge-std/lib/ds-test/src/ | ||
elliptic-curve-solidity/=lib/elliptic-curve-solidity/ | ||
forge-std/=lib/forge-std/src/ | ||
foundry-devops/=lib/foundry-devops/ | ||
@openzeppelin/contracts/=lib/openzeppelin-contracts/contracts/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
pragma solidity ^0.8.25; | ||
|
||
import {Script} from "forge-std/Script.sol"; | ||
import {Tools} from "../src/Tools.sol"; | ||
import {Strings} from "@openzeppelin/contracts/utils/Strings.sol"; | ||
|
||
contract AddressReaderWriter is Script { | ||
function writeContractAddress( | ||
string memory contractName, | ||
address contractAddress | ||
) public { | ||
string memory addressFileName = string.concat( | ||
"./temp/", | ||
contractName, | ||
".", | ||
Strings.toString(block.chainid), | ||
".address" | ||
); | ||
string memory addressStr = Strings.toHexString(contractAddress); | ||
vm.writeFile(addressFileName, addressStr); | ||
} | ||
|
||
function readContractAddress( | ||
string memory contractName | ||
) public returns (address) { | ||
string memory addressFileName = string.concat( | ||
"./temp/", | ||
contractName, | ||
".", | ||
Strings.toString(block.chainid), | ||
".address" | ||
); | ||
string memory contractAddressStr = vm.readLine(addressFileName); | ||
address contractAddress = Tools.toAddress(contractAddressStr); | ||
return contractAddress; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,20 @@ | ||
// SPDX-LICENSE-IDENTIFIER: MIT | ||
|
||
pragma solidity ^0.8.19; | ||
pragma solidity ^0.8.25; | ||
|
||
import { Script } from "forge-std/Script.sol"; | ||
import {console} from "forge-std/console.sol"; | ||
import {BTCDepositAddressDeriver} from "../src/BTCDepositAddressDeriver.sol"; | ||
import {Tools} from "../src/Tools.sol"; | ||
import {Strings} from "@openzeppelin/contracts/utils/Strings.sol"; | ||
import {AddressReaderWriter} from "./AddressReaderWriter.s.sol"; | ||
|
||
contract Deploy is Script { | ||
contract Deploy is Script, AddressReaderWriter { | ||
function run() external returns (BTCDepositAddressDeriver) { | ||
vm.startBroadcast(); | ||
BTCDepositAddressDeriver btcDepositAddressDeriver = new BTCDepositAddressDeriver(); | ||
vm.stopBroadcast(); | ||
writeContractAddress("BTCDepositAddressDeriver", address(btcDepositAddressDeriver)); | ||
return btcDepositAddressDeriver; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
// SPDX-License-Identifier: MIT | ||
|
||
pragma solidity ^0.8.25; | ||
|
||
import {Script} from "forge-std/Script.sol"; | ||
import {console} from "forge-std/console.sol"; | ||
import {BTCDepositAddressDeriver} from "../src/BTCDepositAddressDeriver.sol"; | ||
import {Tools} from "../src/Tools.sol"; | ||
import {AddressReaderWriter} from "./AddressReaderWriter.s.sol"; | ||
|
||
contract GetBtcAddr is Script, AddressReaderWriter { | ||
function run() external { | ||
// get contract address | ||
// if environmental variable is set then use its value | ||
// otherwise try get value from the latest deployment | ||
address contractAddress; | ||
string memory contractAddressStr = vm.envOr( | ||
"CONTRACT_ADDR", | ||
string("") | ||
); | ||
if (!Tools.areStringsEqual(contractAddressStr, "")) { | ||
contractAddress = vm.envAddress("CONTRACT_ADDR"); | ||
} else { | ||
contractAddress = readContractAddress( | ||
"BTCDepositAddressDeriver" | ||
); | ||
} | ||
console.log("contractAddress", contractAddress); | ||
|
||
address ethAddr = vm.envAddress("ETH_ADDR"); | ||
console.log("ethAddr:", ethAddr); | ||
|
||
BTCDepositAddressDeriver deriver = BTCDepositAddressDeriver( | ||
contractAddress | ||
); | ||
string memory btcAddr = deriver.getBTCDepositAddress(ethAddr); | ||
console.log("btcAddr:", btcAddr); | ||
|
||
string memory btcAddrFileName = vm.envOr( | ||
"BTC_ADDR_FILE", | ||
string("") | ||
); | ||
if (!Tools.areStringsEqual(btcAddrFileName, "")) { | ||
vm.writeFile(btcAddrFileName, btcAddr); | ||
} | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.