organizing directories

This commit is contained in:
bt3gl 2022-04-12 02:15:14 +04:00
parent fef58f8b85
commit 704297afbd
13 changed files with 0 additions and 0 deletions

View file

@ -1,12 +0,0 @@
## 👾 Basic Solidity concepts
<br>
### Interfaces
* There are at least 2 reasons why you might use inheritance in smart contract developmnet. First, it allows changes in one parent contract to be reflected in child contracts. Second, it allow you to reuse code and reduce overall program length.
* Interfaces cannot define state variables or constructors, functions have to be external, and interfaces cannot themselves inherit from other contracts.
<br>
### Reentrancy

View file

@ -1,54 +0,0 @@
## Remix IDE
Remix IDE is an open source web3 application and it's used for the entire journey of smart contract development.
<br>
<img width="414" alt="Screen Shot 2022-03-10 at 5 57 22 PM" src="https://user-images.githubusercontent.com/1130416/157715032-63dfbe5d-292d-48e3-8594-04902fb008f6.png">
<br>
* Everything in Remix is a plugin. The plugin mamanger is the place to load functionalities and create your own plugins.
* By default, Remix stores files in Workspaces, which are folders in the browser's local storage.
* You can publish all files from current workspace to a gist, using the Gist API.
#### Compiler (Solidity)
* You can compile (and deploy) contracts with versions of Solidity older than 0.4.12. However, the older compilers used a legacy AST.
* The "fork selection" dropdown list allows to compile code against a specific ehtereum hard fork.
#### Optimization
* The optimizer tries to simplify complicated expressions, which reduces both code size and execution cost. It can reduce gas needed for contract deployment as well as for external calls made to the contract.
#### Environment
* `JavaScript VM`: All transactions will be executed in a sandbox blockchain in the browser.
* `Injected Provider`: Metamaask is an example of a profiver that inject web3.
* `Web3 Provider`: Remix will connect to a remote node (you need to provide the URL to the selected provider: geth, parity or any ethereum client)
#### Setup
* Gas Limit: sets the amount of ETH, WEI, GWEI that is sent to ta contract or a payable function.
* Deploy: sends a transaction that deplpys the selected contract.
* atAdress: used to access a contract whtat has already been deployed (does not cost gas).
* To interact with a contract using the ABI, create a new file in Remix, with extension `.abi`.
* The Recorder is a tool used to save a bunch of transactions in a JSON file and rerun them later either in the same environment or in another.
* The Debugger shows the contract's state while stepping through a transaction.
* Using generated sources will make it easier to audit your contracts.
* Static code analysis can be done by a plugin, so that you can examine the code for security vulnerabilities, bad development practices, etc.
* Hardhat integration can be done with `hardhat.config.js` (Hardhat websocket listener should run at `65522`). Hardhat provider is a plugin for Remix IDE.
#### Generate artifacts
When a compilation for a Solidity file succeeds, Remix creates three Json files for each compiled contract, that can be seen in the `File Explorers plugin`:
1. `artifacts/<contractName>.json`: contains links to libraries, the bytecode, gas estimation, the ABI.
2. `articfacts/<contractName_metadata>.json`: contains the metadata from the output of Solidity compilation.
3. `artifcats/build-info/<dynamic_hash>.json`: contains info about `solc` compiler version, compiler input and output.

View file

@ -1,63 +0,0 @@
## Basic Unit testing
<br>
Functions in a test file to make testing more structural:
* `beforeEach()` - Runs before each test
* `beforeAll()` - Runs before all tests
* `afterEach()` - Runs after each test
* `afterAll()` - Runs after all tests
<br>
A generic unit testing file looks like:
```
pragma solidity >=0.4.22 <0.8.0;
import "remix_tests.sol"; // this import is automatically injected by Remix.
import "remix_accounts.sol";
// Import here the file to test.
// File name has to end with '_test.sol', this file can contain more than one testSuite contracts
contract testSuite {
/// 'beforeAll' runs before all other tests
/// More special functions are: 'beforeEach', 'beforeAll', 'afterEach' & 'afterAll'
function beforeAll() public {
// Here should instantiate tested contract
Assert.equal(uint(1), uint(1), "1 should be equal to 1");
}
function checkSuccess() public {
// Use 'Assert' to test the contract,
// See documentation: https://remix-ide.readthedocs.io/en/latest/assert_library.html
Assert.equal(uint(2), uint(2), "2 should be equal to 2");
Assert.notEqual(uint(2), uint(3), "2 should not be equal to 3");
}
function checkSuccess2() public pure returns (bool) {
// Use the return value (true or false) to test the contract
return true;
}
function checkFailure() public {
Assert.equal(uint(1), uint(2), "1 is not equal to 2");
}
/// Custom Transaction Context
/// See more: https://remix-ide.readthedocs.io/en/latest/unittesting.html#customization
/// #sender: account-1
/// #value: 100
function checkSenderAndValue() public payable {
// account index varies 0-9, value is in wei
Assert.equal(msg.sender, TestsAccounts.getAccount(1), "Invalid sender");
Assert.equal(msg.value, 100, "Invalid value");
}
}
```
Note that ine can input custom values for `msg.sender` & `msg.value` of transaction using NatSpec comments.