Github
작성한 모든 문제 코드는 아래 github에서 확인 가능
https://github.com/Ho-Ya-Ho/mogakso
명령어 모음
- foundryup : foundry update
- forge init [폴더이름] : solidity 개발에 필요한 기본 디렉토리 생성
- forge create : 컨트렉트에 배포하는 명령어
- ex) forge create src/Attack.sol:Attack → 헤당 경로에 있는 Attack 컨트랙트를 배포 하겠다
- —rpc-url : RPC url 적는 옵션
- —private-key : private key 적는 옵션
- —constructor-args : 생성자의 argument 넣는 옵션
- —broadcast : 실제 컨트렉트에 트랜잭션을 날리는 옵션
- forge test : test 할 떄 사용하는 명령어
- ex) forge test --match-test test_I -vvvv
- cast send : 컨트렉트에 배포되어있는 함수를 호출하여 트랜잭션을 보내는 명령어
- ex) cast send [Attack 컨트렉스 주소] --rpc-url [RPC-URL] --private-key [private-key] "attack()"
- cast call : 컨트렉트에 배포되어있는 변수 확인하는 명령어
- ex) cast call [문제 instance address] --rpc-url [RPC-URL] "consecutiveWins()"
- cast storage : 스토리지를 확인하는 명령어
- ex) cast storage [문제 instance address] --rpc-url [RPC-URL] 0
- cast compute-address : 특정 주소가 CREATE로 배포하는 컨트랙트의 주소를 계산하는 명령어
- ex) cast compute-address [문제 instance address] --nonce 1
디버깅 방법 → 나중에는 script로 디버깅해서 문제품
아래처럼 console을 import하고 찍어볼 수 있다.
// src 내부
import "forge-std/console.sol";
function sendAllocation(address payable allocator) public {
require(allocations[allocator] > 0);
allocator.transfer(allocations[allocator]);
console.log("allocator : %s", address(allocator));
}
// forge 명령어
forge test --match-test test_I -vvvv
> [여기에 뜸]
// test 폴더 내부에서 sendAllocation() 함수를 호출하는 테스트 코드를 작성한 후 실행하면 된다.