-
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.
Week2 homework completed in foundry instead of hardhat. Stored in a s…
…eparate folder.
- Loading branch information
Struct
authored and
Struct
committed
May 8, 2023
1 parent
ea37f25
commit 18080a0
Showing
71 changed files
with
13,873 additions
and
0 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 |
---|---|---|
@@ -0,0 +1,34 @@ | ||
name: test | ||
|
||
on: workflow_dispatch | ||
|
||
env: | ||
FOUNDRY_PROFILE: ci | ||
|
||
jobs: | ||
check: | ||
strategy: | ||
fail-fast: true | ||
|
||
name: Foundry project | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v3 | ||
with: | ||
submodules: recursive | ||
|
||
- name: Install Foundry | ||
uses: foundry-rs/foundry-toolchain@v1 | ||
with: | ||
version: nightly | ||
|
||
- name: Run Forge build | ||
run: | | ||
forge --version | ||
forge build --sizes | ||
id: build | ||
|
||
- name: Run Forge tests | ||
run: | | ||
forge test -vvv | ||
id: test |
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,14 @@ | ||
# Compiler files | ||
cache/ | ||
out/ | ||
|
||
# Ignores development broadcast logs | ||
!/broadcast | ||
/broadcast/*/31337/ | ||
/broadcast/**/dry-run/ | ||
|
||
# Docs | ||
docs/ | ||
|
||
# Dotenv file | ||
.env |
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,3 @@ | ||
[submodule "lib/forge-std"] | ||
path = lib/forge-std | ||
url = https://github.com/foundry-rs/forge-std |
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,133 @@ | ||
# Group 1 - Encode Solidity Bootcamp Homework - Week 2 (Alternate) | ||
Attempted to work through the homework in foundry instead of hardhat. | ||
|
||
## Some Difficulties: | ||
Solidity try-catch does not behave in the same way as other common languages. | ||
Had to run transactions that resulted in errors/reverts in tests instead of the script itself. | ||
|
||
## On chain transactions | ||
### Deploying contract | ||
Hash: 0xcdbd798854e8eac8c8f7a462ef0f0f5d554c23c9985af211635f054216362712 | ||
Contract Address: 0xcd863aef140259a94c6a4040b3d7f968bf0bdd85 | ||
Block: 3443830 | ||
Paid: 0.00191210100637367 ETH (637367 gas * 3.00000001 gwei) | ||
|
||
### Giving user 2 right to vote | ||
Hash: 0xd54ec83e0a126ed747285c25ba982b3f7099e3e02c9d377175fdbad346563622 | ||
Block: 3443831 | ||
Paid: 0.000145167000532279 ETH (48389 gas * 3.000000011 gwei) | ||
|
||
### Giving user 3 right to vote | ||
Hash: 0x638b516711a5f115e8f0915bb42a95be8eb633e132b2a25ad648ccf4370ce198 | ||
Block: 3443832 | ||
Paid: 0.000145167000532279 ETH (48389 gas * 3.000000011 gwei) | ||
|
||
### Chairperson voting for proposal one | ||
Hash: 0x6a74abde6f4e8fa2f18c08a385d3d94f904c124303628bc06eeb7df73bc42918 | ||
Block: 3443833 | ||
Paid: 0.000277557001017709 ETH (92519 gas * 3.000000011 gwei) | ||
|
||
### User 2 votes for proposal 1 | ||
Hash: 0xb76887a667ce544be7b7e715f6d4f5d53d0c04626668f757225b6f5a3e81ca17 | ||
Block: 3443834 | ||
Paid: 0.000226257000829609 ETH (75419 gas * 3.000000011 gwei) | ||
|
||
### User 3 delegates away right to vote | ||
Hash: 0x6281770a2ddefd516ff6fd4b1940ba9ea523073e0376d471396058cffe2b88cc | ||
Block: 3443835 | ||
Paid: 0.00018128400060428 ETH (60428 gas * 3.00000001 gwei) | ||
|
||
### View functions | ||
Winning proposal number: 1 | ||
Winner name: ProposalOne | ||
|
||
## Test Cases | ||
``` | ||
Traces: | ||
[124889] BallotTest::testDelegateAfterVoting() | ||
├─ [0] console::log(user2 attempts to delegate to another address after voting) [staticcall] | ||
│ └─ ← () | ||
├─ [32241] Chairperson::giveRightToVote(User: [0x2e234DAe75C793f67A35089C9d99245E1C58470b]) | ||
│ ├─ [26957] Ballot::giveRightToVote(User: [0x2e234DAe75C793f67A35089C9d99245E1C58470b]) | ||
│ │ └─ ← () | ||
│ └─ ← () | ||
├─ [69995] User::vote(1) | ||
│ ├─ [67315] Ballot::vote(1) | ||
│ │ └─ ← () | ||
│ └─ ← () | ||
├─ [0] VM::expectRevert(You already voted.) | ||
│ └─ ← () | ||
├─ [1546] User::delegate(User: [0xF62849F9A0B5Bf2913b396098F7c7019b51A820a]) | ||
│ ├─ [776] Ballot::delegate(User: [0xF62849F9A0B5Bf2913b396098F7c7019b51A820a]) | ||
│ │ └─ ← "You already voted." | ||
│ └─ ← "You already voted." | ||
└─ ← () | ||
[PASS] testDelegateToSelf() (gas: 52253) | ||
Logs: | ||
user2 attempts to delegate to self | ||
Traces: | ||
[52253] BallotTest::testDelegateToSelf() | ||
├─ [0] console::log(user2 attempts to delegate to self) [staticcall] | ||
│ └─ ← () | ||
├─ [32241] Chairperson::giveRightToVote(User: [0x2e234DAe75C793f67A35089C9d99245E1C58470b]) | ||
│ ├─ [26957] Ballot::giveRightToVote(User: [0x2e234DAe75C793f67A35089C9d99245E1C58470b]) | ||
│ │ └─ ← () | ||
│ └─ ← () | ||
├─ [0] VM::expectRevert(Self-delegation is disallowed.) | ||
│ └─ ← () | ||
├─ [3580] User::delegate(User: [0x2e234DAe75C793f67A35089C9d99245E1C58470b]) | ||
│ ├─ [810] Ballot::delegate(User: [0x2e234DAe75C793f67A35089C9d99245E1C58470b]) | ||
│ │ └─ ← "Self-delegation is disallowed." | ||
│ └─ ← "Self-delegation is disallowed." | ||
└─ ← () | ||
[PASS] testDelegateWithNoRight() (gas: 21296) | ||
Logs: | ||
user2 attempts to delegate to another address | ||
Traces: | ||
[21296] BallotTest::testDelegateWithNoRight() | ||
├─ [0] console::log(user2 attempts to delegate to another address) [staticcall] | ||
│ └─ ← () | ||
├─ [0] VM::expectRevert(You have no right to vote) | ||
│ └─ ← () | ||
├─ [7908] User::delegate(User: [0xF62849F9A0B5Bf2913b396098F7c7019b51A820a]) | ||
│ ├─ [2638] Ballot::delegate(User: [0xF62849F9A0B5Bf2913b396098F7c7019b51A820a]) | ||
│ │ └─ ← "You have no right to vote" | ||
│ └─ ← "You have no right to vote" | ||
└─ ← () | ||
[PASS] testGiveRightToVoteWithNoRight() (gas: 21365) | ||
Logs: | ||
user2 attempts to give right to vote | ||
Traces: | ||
[21365] BallotTest::testGiveRightToVoteWithNoRight() | ||
├─ [0] console::log(user2 attempts to give right to vote) [staticcall] | ||
│ └─ ← () | ||
├─ [0] VM::expectRevert(Only chairperson can give right to vote.) | ||
│ └─ ← () | ||
├─ [7855] User::giveRightToVote(User: [0xF62849F9A0B5Bf2913b396098F7c7019b51A820a]) | ||
│ ├─ [2560] Ballot::giveRightToVote(User: [0xF62849F9A0B5Bf2913b396098F7c7019b51A820a]) | ||
│ │ └─ ← "Only chairperson can give right to vote." | ||
│ └─ ← "Only chairperson can give right to vote." | ||
└─ ← () | ||
[PASS] testVoteWithNoRight() (gas: 21138) | ||
Logs: | ||
user2 attempts to delegate to another address | ||
Traces: | ||
[21138] BallotTest::testVoteWithNoRight() | ||
├─ [0] console::log(user2 attempts to delegate to another address) [staticcall] | ||
│ └─ ← () | ||
├─ [0] VM::expectRevert(Has no right to vote) | ||
│ └─ ← () | ||
├─ [7709] User::vote(1) | ||
│ ├─ [2521] Ballot::vote(1) | ||
│ │ └─ ← "Has no right to vote" | ||
│ └─ ← "Has no right to vote" | ||
└─ ← () | ||
``` |
109 changes: 109 additions & 0 deletions
109
Week2 (Alternate)/Ballot/broadcast/Deployment.s.sol/11155111/run-1683548982.json
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,109 @@ | ||
{ | ||
"transactions": [ | ||
{ | ||
"hash": "0x5244227517fde4724f6097009cd4468025ac9e6d5384cf81d51ef6727115da74", | ||
"transactionType": "CALL", | ||
"contractName": null, | ||
"contractAddress": null, | ||
"function": null, | ||
"arguments": null, | ||
"rpc": "https://rpc2.sepolia.org", | ||
"transaction": { | ||
"type": "0x02", | ||
"from": "0x9620daf4fe148e8dcb58745f35be24ae30503535", | ||
"value": "0x0", | ||
"data": "0x608060405234801561001057600080fd5b506040516109c83803806109c883398101604081905261002f916100e2565b600080546001600160a01b03191633908117825581526001602081905260408220555b81518110156100c5576002604051806040016040528084848151811061007a5761007a61019f565b602090810291909101810151825260009181018290528354600181810186559483529181902083516002909302019182559190910151910155806100bd816101b5565b915050610052565b50506101dc565b634e487b7160e01b600052604160045260246000fd5b600060208083850312156100f557600080fd5b82516001600160401b038082111561010c57600080fd5b818501915085601f83011261012057600080fd5b815181811115610132576101326100cc565b8060051b604051601f19603f83011681018181108582111715610157576101576100cc565b60405291825284820192508381018501918883111561017557600080fd5b938501935b828510156101935784518452938501939285019261017a565b98975050505050505050565b634e487b7160e01b600052603260045260246000fd5b6000600182016101d557634e487b7160e01b600052601160045260246000fd5b5060010190565b6107dd806101eb6000396000f3fe608060405234801561001057600080fd5b50600436106100885760003560e01c8063609ff1bd1161005b578063609ff1bd1461010d5780639e7b8d6114610123578063a3ec138d14610136578063e2ba53f0146101a757600080fd5b80630121b93f1461008d578063013cf08b146100a25780632e4176cf146100cf5780635c19a95c146100fa575b600080fd5b6100a061009b366004610700565b6101af565b005b6100b56100b0366004610700565b6102a9565b604080519283526020830191909152015b60405180910390f35b6000546100e2906001600160a01b031681565b6040516001600160a01b0390911681526020016100c6565b6100a0610108366004610719565b6102d7565b610115610538565b6040519081526020016100c6565b6100a0610131366004610719565b6105b5565b610178610144366004610719565b600160208190526000918252604090912080549181015460029091015460ff82169161010090046001600160a01b03169084565b6040516100c6949392919093845291151560208401526001600160a01b03166040830152606082015260800190565b6101156106cd565b336000908152600160205260408120805490910361020b5760405162461bcd60e51b8152602060048201526014602482015273486173206e6f20726967687420746f20766f746560601b60448201526064015b60405180910390fd5b600181015460ff16156102515760405162461bcd60e51b815260206004820152600e60248201526d20b63932b0b23c903b37ba32b21760911b6044820152606401610202565b6001818101805460ff191690911790556002808201839055815481549091908490811061028057610280610749565b906000526020600020906002020160010160008282546102a09190610775565b90915550505050565b600281815481106102b957600080fd5b60009182526020909120600290910201805460019091015490915082565b33600090815260016020526040812080549091036103375760405162461bcd60e51b815260206004820152601960248201527f596f752068617665206e6f20726967687420746f20766f7465000000000000006044820152606401610202565b600181015460ff16156103815760405162461bcd60e51b81526020600482015260126024820152712cb7ba9030b63932b0b23c903b37ba32b21760711b6044820152606401610202565b336001600160a01b038316036103d95760405162461bcd60e51b815260206004820152601e60248201527f53656c662d64656c65676174696f6e20697320646973616c6c6f7765642e00006044820152606401610202565b6001600160a01b03828116600090815260016020819052604090912001546101009004161561047d576001600160a01b03918216600090815260016020819052604090912001546101009004909116903382036104785760405162461bcd60e51b815260206004820152601960248201527f466f756e64206c6f6f7020696e2064656c65676174696f6e2e000000000000006044820152606401610202565b6103d9565b6001600160a01b03821660009081526001602081905260409091208054909111156104a757600080fd5b600182810180546001600160a81b0319166101006001600160a01b03871602178217905581015460ff1615610519578154600282810154815481106104ee576104ee610749565b9060005260206000209060020201600101600082825461050e9190610775565b909155506105339050565b81548154829060009061052d908490610775565b90915550505b505050565b600080805b6002548110156105b057816002828154811061055b5761055b610749565b906000526020600020906002020160010154111561059e576002818154811061058657610586610749565b90600052602060002090600202016001015491508092505b806105a88161078e565b91505061053d565b505090565b6000546001600160a01b031633146106205760405162461bcd60e51b815260206004820152602860248201527f4f6e6c79206368616972706572736f6e2063616e2067697665207269676874206044820152673a37903b37ba329760c11b6064820152608401610202565b6001600160a01b0381166000908152600160208190526040909120015460ff161561068d5760405162461bcd60e51b815260206004820152601860248201527f54686520766f74657220616c726561647920766f7465642e00000000000000006044820152606401610202565b6001600160a01b038116600090815260016020526040902054156106b057600080fd5b6001600160a01b0316600090815260016020819052604090912055565b600060026106d9610538565b815481106106e9576106e9610749565b906000526020600020906002020160000154905090565b60006020828403121561071257600080fd5b5035919050565b60006020828403121561072b57600080fd5b81356001600160a01b038116811461074257600080fd5b9392505050565b634e487b7160e01b600052603260045260246000fd5b634e487b7160e01b600052601160045260246000fd5b808201808211156107885761078861075f565b92915050565b6000600182016107a0576107a061075f565b506001019056fea2646970667358221220010e485d8aaa54be76f6619707fe2a5a56d4af7e0fffcc7fb5754e19513bb53f64736f6c634300081300330000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000350726f706f73616c5a65726f000000000000000000000000000000000000000050726f706f73616c4f6e6500000000000000000000000000000000000000000050726f706f73616c54776f000000000000000000000000000000000000000000", | ||
"nonce": "0x6b", | ||
"accessList": [] | ||
}, | ||
"additionalContracts": [], | ||
"isFixedGasLimit": false | ||
}, | ||
{ | ||
"hash": null, | ||
"transactionType": "CALL", | ||
"contractName": null, | ||
"contractAddress": null, | ||
"function": null, | ||
"arguments": null, | ||
"rpc": "https://rpc2.sepolia.org", | ||
"transaction": { | ||
"type": "0x02", | ||
"from": "0x58955872d346d19e5c7682a9f9317c4db7338fe0", | ||
"to": "0x9e79e4dfd1f3f5b616aae42ddd5d59ab10466acb", | ||
"value": "0x0", | ||
"data": "0x0121b93f0000000000000000000000000000000000000000000000000000000000000001", | ||
"nonce": "0x1", | ||
"accessList": [] | ||
}, | ||
"additionalContracts": [], | ||
"isFixedGasLimit": false | ||
}, | ||
{ | ||
"hash": null, | ||
"transactionType": "CALL", | ||
"contractName": null, | ||
"contractAddress": null, | ||
"function": null, | ||
"arguments": null, | ||
"rpc": "https://rpc2.sepolia.org", | ||
"transaction": { | ||
"type": "0x02", | ||
"from": "0x58955872d346d19e5c7682a9f9317c4db7338fe0", | ||
"to": "0x9e79e4dfd1f3f5b616aae42ddd5d59ab10466acb", | ||
"value": "0x0", | ||
"data": "0x5c19a95c000000000000000000000000aaf640f8a06bc6a23f8f7b93618884eeeaac2276", | ||
"nonce": "0x2", | ||
"accessList": [] | ||
}, | ||
"additionalContracts": [], | ||
"isFixedGasLimit": false | ||
}, | ||
{ | ||
"hash": null, | ||
"transactionType": "CALL", | ||
"contractName": null, | ||
"contractAddress": null, | ||
"function": null, | ||
"arguments": null, | ||
"rpc": "https://rpc2.sepolia.org", | ||
"transaction": { | ||
"type": "0x02", | ||
"from": "0x58955872d346d19e5c7682a9f9317c4db7338fe0", | ||
"to": "0x9e79e4dfd1f3f5b616aae42ddd5d59ab10466acb", | ||
"value": "0x0", | ||
"data": "0x9e7b8d61000000000000000000000000aaf640f8a06bc6a23f8f7b93618884eeeaac2276", | ||
"nonce": "0x3", | ||
"accessList": [] | ||
}, | ||
"additionalContracts": [], | ||
"isFixedGasLimit": false | ||
} | ||
], | ||
"receipts": [ | ||
{ | ||
"transactionHash": "0x5244227517fde4724f6097009cd4468025ac9e6d5384cf81d51ef6727115da74", | ||
"transactionIndex": "0x0", | ||
"blockHash": "0x284b0f42e00e2e947a4aa2c48c98fbcbb81575b489c3052dc7d8d005db67064e", | ||
"blockNumber": "0x348af5", | ||
"from": "0x9620daf4fE148e8dCB58745f35BE24AE30503535", | ||
"to": null, | ||
"cumulativeGasUsed": "0x9b9b7", | ||
"gasUsed": "0x9b9b7", | ||
"contractAddress": "0x9e79e4dfD1f3F5b616AAE42DDd5d59Ab10466ACb", | ||
"logs": [], | ||
"status": "0x1", | ||
"logsBloom": "0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", | ||
"type": "0x2", | ||
"effectiveGasPrice": "0xb2d05e09" | ||
} | ||
], | ||
"libraries": [], | ||
"pending": [], | ||
"path": "/Users/struct/Desktop/SmartContracts/encode/bootcamp1/Encode-Solidity-Bootcamp/Week2 (Alternate)/Ballot/broadcast/Deployment.s.sol/11155111/run-latest.json", | ||
"returns": {}, | ||
"timestamp": 1683548982, | ||
"chain": 11155111, | ||
"multi": false, | ||
"commit": "b64ef6e" | ||
} |
Oops, something went wrong.