# [Setup] Additional Case
::: info
This setup is extend from `FiroVM setup Guide v2.2`
to cover more test case
:::
## 1. Case Add Miner Failed
### [ Beginning Setup ]
#### 1) Preparing Setup
```bash
CLI1='docker exec -it firovm-tool-node1-1 firovm-cli --datadir=/firovm'
CLI2='docker exec -it firovm-tool-node2-1 firovm-cli --datadir=/firovm'
```
#### 2) Setup Wallet
```bash
node ./build/index.js testing:init --wallet
```
#### 3) Setup Miner
```bash
node ./build/index.js testing:init --govcontracts
```
#### 4) Create Wallet in node2
```bash
$CLI2 createwallet ''
```
#### 5) Create Miners
```bash
miners=10
for i in $(seq 1 $miners)
do
$CLI2 getnewaddress 'miner' >> miners.txt
done
MINER=$(tail -n 1 miners.txt)
echo $MINER
```
### [ Starting Test ]
::: warning
$MINER is the miner address that you want to add
:::
### 1.1 Failed Proposer is Not Admin
```
node ./build/index.js testing:addminer $MINER ChangeAdmin1ToNewUser
```
**Setup:**
- Using the same method from the guide named `FiroVM_setup_Guide_v2.2` before the process `Setup wallet`.
#### 1.1.1 We are not going to add admin2 to the ADMIN_ROLE.
- We are going to change the proposer from admin1 to admin2.
#### 1.1.2 We are gonna add admin2 to the GOV_ROLE.
- We are going to change the proposer from admin1 to admin2.
**Result:**
- Shall not return the proposal ID (cannot create a proposal).
**Pattern:**
- In 27th line -> Error: fail to propose: exception with Revert and message **Not an admin** txid ...
```bash=
INFO] starting test addminer testAddMinerChangeAdmin1ToNewUser
[INFO] miner = TMfoNJbqoXDLUt5k99uLkzrECjBaSsTStz
[INFO] admin1 = TDNKtaGuMhWH2CsUFNPjTt2u8ydRwoHgai, admin2 = TPT6h5wiwSkboiy4my6J3p2BPCgbZKS3dU
[INFO] new user = TXeTo73Mv7fkhLDFoCpShRwy2tpRMrh6LC
[INFO] - proposeMiner:
*** change admin1 to new user ***
index.js testaddminer <miner> <test-module>
test funding and register utxos
Positionals:
miner miner to fund and register [string] [required]
testModule choose addMiner module [string]
Options:
--version Show version number [boolean]
-e, --env environment variable file location [default: ".env"]
--ignoreerr ignore error while execute [default: false]
--loglevel set log level, all possible values are `debug`, `info`,
`warn` and `error` [default: "info"]
--help Show help [boolean]
-u, --utxos Number of utxo to generate [default: 50]
-f, --funder Funder of address or label to address if this is not set,
admin1 will be used [string]
Error: fail to propose: exception with Revert and message Not an admin txid c60b49a5f58ba3bb4f2a1bfd8378ca5a72a7a60409d89584d42e948f017d4526
at /root/workspace/firovm-tool/build/testMiner.js:129:19
at Generator.next (<anonymous>)
at fulfilled (/root/workspace/firovm-tool/build/testMiner.js:5:58)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
```
### 1.2 Failed Voter is Not Admin or Gov
```
node ./build/index.js testing:addminer $MINER ChangeAdmin2ToNewUser
```
**Setup:**
- Using the same setup as in the guide, this time follow the instruction by adding admin2 to the ADMIN_ROLE but this time we create the admin3 account and not add it to ADMIN_ROLE
- Create proposal by admin1
- Attempt to vote on a proposal using the unauthorized voter (admin3).
**Result:**
- Shall not accept the vote and return an error message indicating that the voter must be an admin or government entity.
**Pattern:**
- In 29th line -> Error: fail to vote: exception with Revert and message **Not a admin or gov account**
```bash=
[INFO] starting test addminer testAddMinerChangeAdmin2ToNewUser
[INFO] miner = TMfoNJbqoXDLUt5k99uLkzrECjBaSsTStz
[INFO] admin1 = TDNKtaGuMhWH2CsUFNPjTt2u8ydRwoHgai, admin2 = TPT6h5wiwSkboiy4my6J3p2BPCgbZKS3dU
[INFO] new user = TKD9xF5BogE7CE12E4Uf61d2yHxtafSGcB
[INFO] - proposeMiner:
[INFO] - proposalId: 477d1b812861d440b341185be08c75b1e9a8b0bec96b699b521da4b272a2cc04, txid = 9058157b27a20c11676913658079bad5ac46863c899bc4c151cd0b1669dd619e
[INFO] - vote: success
*** change admin2 to new user ***
index.js testaddminer <miner> <test-module>
test funding and register utxos
Positionals:
miner miner to fund and register [string] [required]
testModule choose addMiner module [string]
Options:
--version Show version number [boolean]
-e, --env environment variable file location [default: ".env"]
--ignoreerr ignore error while execute [default: false]
--loglevel set log level, all possible values are `debug`, `info`,
`warn` and `error` [default: "info"]
--help Show help [boolean]
-u, --utxos Number of utxo to generate [default: 50]
-f, --funder Funder of address or label to address if this is not set,
admin1 will be used [string]
Error: fail to vote: exception with Revert and message Not a admin or gov account
at /root/workspace/firovm-tool/build/testMiner.js:84:19
at Generator.next (<anonymous>)
at fulfilled (/root/workspace/firovm-tool/build/testMiner.js:5:58)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
```
- If you still use old miner then it will occur the new error after executed and the same line (29th) -> Error: fail to propose: exception with Revert and message **Miner Proposal already exist** txid ...
### 1.3 Failed Voter vote reject >= accept
```
node ./build/index.js testing:addminer $MINER ChangeYesVoteToAgainstVote
```
**Step:**
- Using the authorized voter (admin2), cast a vote that rejects the proposal.
**Result:**
- Shall change the proposal status to "Rejected."
**Pattern:**
- In 24th line -> `status: 4n,`
```bash=
[INFO] starting test addminer testAddMinerChangeYesVoteToAgainstVote
[INFO] miner = TMfoNJbqoXDLUt5k99uLkzrECjBaSsTStz
[INFO] admin1 = TDNKtaGuMhWH2CsUFNPjTt2u8ydRwoHgai, admin2 = TPT6h5wiwSkboiy4my6J3p2BPCgbZKS3dU
[INFO] new user = TKJKY7ua21Vn5K2ujmo1HN4hECuWMR8zJ5
[INFO] - proposeMiner:
[INFO] - proposalId: 1fb04b8ace3fb4c530bfbee9bcb35fc952f44a0b02a0f2c616f7405fb69716f6, txid = fb4b6abad7206687abfafddc7a72fcb32a27b99d1a0d45bd831ef2bd3fc62087
[INFO] - vote: Against
[INFO] change vote of admin2 from YES to Against vote
[INFO] - txid of admin2: 4598cbc69f65e112820681e8a9ed6386be327cef43e858f3c07e9688baaa2c25
[INFO] - txid of admin3: 28e1423ab0503d6554f896e09c6f806efa4470aa8f118c1bb286ac75b00d91d3
[INFO] - txid of admin4: 7fe524bfabd1d36e7f63b1129af816aea9d98d304f4b1d8f4ace4ca89555907d
[INFO] ** get proposal info ***
{
'0': '0x2547B1c78a2E25AE32406bD6243bD80BF0f5EC01',
'1': 1692951625n,
'2': 4n,
'3': 3n,
'4': 1n,
'5': 0n,
'6': '0x66567DAca9f8e660a73C8EF9acb30b462A49B413',
__length__: 7,
proposer: '0x2547B1c78a2E25AE32406bD6243bD80BF0f5EC01',
startTime: 1692951625n,
status: 4n,
againstVotes: 3n,
forVotes: 1n,
abstainVotes: 0n,
minerAddress: '0x66567DAca9f8e660a73C8EF9acb30b462A49B413'
}
[INFO] status of proposal = 4n
[INFO] proposal will be rejected
[INFO] end of testing against votes
```
### 1.4 Failed Voter Vote Accepts but Proposer Timeout
:::warning
This case need chain running in the `regtest` , because we using `setmocktime` command that can only change in `regtest`
:::
```
node ./build/index.js testing:addminer $MINER Timeout
```
**Setup:**
- Using the authorized voter, cast a vote that accepts the proposal.
- Simulate or wait for the proposer timeout period.
**Result:**
- Shall change the proposal status to "Expired."
**Pattern:**
- In 48th line -> Error: fail to vote: exception with Revert and message **Voting is over**
```bash=
[INFO] starting test addminer testAddMinerTimeout
[INFO] miner = TMfoNJbqoXDLUt5k99uLkzrECjBaSsTStz
[INFO] admin1 = TDNKtaGuMhWH2CsUFNPjTt2u8ydRwoHgai, admin2 = TPT6h5wiwSkboiy4my6J3p2BPCgbZKS3dU
[INFO] new user = TB2pyzS8nxCyRWchqbv3aWtyMc4CkZjCMK
[INFO] - proposeMiner:
[INFO] - proposalId: 51896fc61bf7528c63e726033a51b0571367484a7499ddf6c8a88fe61a7b92b6, txid = d763c1699344060c865e00a322106bf559169aff6cd06b2c821ae3d463ca5a1c
[INFO] *** before ***
{
'0': '0x2547B1c78a2E25AE32406bD6243bD80BF0f5EC01',
'1': 1813934520n,
'2': 0n,
'3': 0n,
'4': 1n,
'5': 0n,
'6': '0x0ba768da96A7a82222839CF29E411b2829497C6A',
__length__: 7,
proposer: '0x2547B1c78a2E25AE32406bD6243bD80BF0f5EC01',
startTime: 1813934520n,
status: 0n,
againstVotes: 0n,
forVotes: 1n,
abstainVotes: 0n,
minerAddress: '0x0ba768da96A7a82222839CF29E411b2829497C6A'
}
[INFO] - ensure to 2434 blocks
[INFO] ensure block done
[INFO] Complete ensure block 2434
[INFO] change vote of admin2,3,4 from YES to Abstrain vote
index.js testaddminer <miner> <test-module>
test funding and register utxos
Positionals:
miner miner to fund and register [string] [required]
testModule choose addMiner module [string]
Options:
--version Show version number [boolean]
-e, --env environment variable file location [default: ".env"]
--ignoreerr ignore error while execute [default: false]
--loglevel set log level, all possible values are `debug`, `info`,
`warn` and `error` [default: "info"]
--help Show help [boolean]
-u, --utxos Number of utxo to generate [default: 50]
-f, --funder Funder of address or label to address if this is not set,
admin1 will be used [string]
Error: fail to vote: exception with Revert and message Voting is over
at /root/workspace/firovm-tool/build/testMiner.js:311:19
at Generator.next (<anonymous>)
at fulfilled (/root/workspace/firovm-tool/build/testMiner.js:5:58)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
```
### 1.5 Failed Voter Does Not Cast Vote (ไม่ลงคะแนน)
```
node ./build/index.js testing:addminer $MINER ChangeYesVoteToAbstrainVote
```
**Setup:**
- Initialize the contract with a proposal but do not cast a vote.
- Wait or simulate the voting period expiring.
**Result:**
- Shall change the proposal status to "Expired" .
**Pattern:**
- In 24th line -> `status: 0n,`
```bash=
[INFO] starting test addminer testAddMinerChangeYesVoteToAbstrainVote
[INFO] miner = TMfoNJbqoXDLUt5k99uLkzrECjBaSsTStz
[INFO] admin1 = TDNKtaGuMhWH2CsUFNPjTt2u8ydRwoHgai, admin2 = TPT6h5wiwSkboiy4my6J3p2BPCgbZKS3dU
[INFO] new user = TC96LMQhP49SVd1A7CVyjHTVVoKrUoXY41
[INFO] - proposeMiner:
[INFO] - proposalId: d793e20522b09a58ee54ae318685de1c64292d8842e9c20b6ff0efea1a5671b1, txid = 249a25b980670bd1b8a94155371f3b97f23aa58d0ea55eb0f645d805c8a5aabb
[INFO] - vote: Abstrain
[INFO] change vote from admin2 from YES to Abstrain vote
[INFO] - txid of admin2: b38c9a7c62fa60a376b6bcd4bbc763709920001d73901924f8ee0b76dd2daee0
[INFO] - txid of admin3: a2fba9f0aab738347bf37c4ec248a04f8d4452ec05fdbef679c5a85ffa6b13d1
[INFO] - txid of admin4: 51cdbfa79ea8a1afcfa82f8c5da013e80acd0cf454b15b233c5a3b5edd4327cc
[INFO] *** get proposal info ***
{
'0': '0x2547B1c78a2E25AE32406bD6243bD80BF0f5EC01',
'1': 1692972258n,
'2': 0n,
'3': 0n,
'4': 1n,
'5': 3n,
'6': '0x17ceD876BcCf7d0e2a5D825f3c7483415CF7b1ef',
__length__: 7,
proposer: '0x2547B1c78a2E25AE32406bD6243bD80BF0f5EC01',
startTime: 1692972258n,
status: 0n,
againstVotes: 0n,
forVotes: 1n,
abstainVotes: 3n,
minerAddress: '0x17ceD876BcCf7d0e2a5D825f3c7483415CF7b1ef'
}
[INFO] status of proposal = 0n
[INFO] end of testing abstrain votes
```
## 2. Case: Remove Miner
### [ Beginning Setup ]
#### 1) Setup Wallet
```bash!
node ./build/index.js init –-wallet
```
#### 2) Setup Miner
```
node ./build/index.js init –-govcontracts
```
### 2.1 Success: Remove UTXO
```
node ./build/index.js testing:removeutxo:success:admin
```
This script will
- run `getnewaddress` to generate 1 user
- call `addMinerForTest` to add user to miner and return utxo
- Call `ensureAdmin` to be a caller
- Call `callRemoveUTXOs` to remove utxo that returned from addMinerForTest. From the authorized address (admin1)
<!-- **Setup**:
- set up the miner with some UTXOs. By doing the 3.2 in the guide
- Call the `removeUTXOs` function with the UTXOs you want to remove. From the authorized address (admin1) -->
**Result**:
```
[INFO] admin1 = TG8HSyPjkyMkkda2hAyKFmFEwokLh4rAxu, admin2 = TM1Siv4r3Zywb6uvFgXk51Ufav1G5d7UAt
[INFO] - proposeMiner:
[INFO] - proposalId: 610a06652bd3cfb40f01a837f06f6e7c0375c17d889b526204ce10d77a4fcc9c, txid = 51452f9a3d99a2d5894c910d2712ccbefa5624c3eabb2b4430d1e9022f9a57b5
[INFO] - vote: success
[INFO] - txid: 83dc4f2cdf340454257b4d6173ec7276c07252a6e88f2225a98100d89c4219a6
[INFO] - callRemoveUTXOs:
[INFO] - to contract: 0000000000000000000000000000000000000880
[INFO] - gas: 1000000
[INFO] - with caller: TG8HSyPjkyMkkda2hAyKFmFEwokLh4rAxu
[INFO] - removeUTXOs success with tx = 7be1efb772bcece0650074b0526a56b5083de674b26ac156c884464f69f53aea
```
- the UTXOs have been removed from `miners` mapping. (getaddressutxos)
### 2.2 Failed: Remove UTXO, Sender is Not Admin
<!-- **Setup**:
- set up the miner with some UTXOs. By doing the 3.2 in the guide
- Call the `callRemoveUTXOs` function with the UTXOs you want to remove. -->
#### 2.2.1 Failed: Remove UTXO, Voter is Not Governance Role
```
node ./build/index.js testing:removeutxo:fail:notgovernance
```
This script will
- run `getnewaddress` to generate 2 user
- user1: call `addMinerForTest` to add user to miner and return utxo
- user2: user who is not governance role and admin role
- call `callRemoveUTXOs` to remove utxo that return from addMinerForTest. From the user who is not governance role and admin role (user2)
**Result**:
```bash=
[INFO] admin1 = TSTtgUx6bBraEKxR8QuCiCffQAYZpAmS5Y, admin2 = TXXW8NbMJ5V8afSzgaCSiignHCzieHg72W
[INFO] - proposeMiner:
[INFO] - proposalId: 0904244157df880a04e8650a3872e3ef3d0a1c6a2a9e0564200a54002c0ac417, txid = 9bbaaad3e2a2df1645add8b3e77724b4c7ad2d2ccd1f53853c4012bf2f3dfb48
[INFO] - vote: success
[INFO] - txid: b567f7561e6b30fff9a77afe926fd59033548b099edc77abf65b367fe1cb0abe
[INFO] - callRemoveUTXOs:
[INFO] - to contract: 0000000000000000000000000000000000000880
[INFO] - gas: 1000000
[INFO] - with caller: TDX9ro1QJHkXfPNQc26cZ6xw3hvX24aB1q
index.js test:removeutxo:fail:governance [<gas>]
Test fail with caller who is not an admin and gov ==> result: message Not an
admin
Options:
--version Show version number [boolean]
-e, --env environment variable file location [default: ".env"]
--ignoreerr ignore error while execute [default: false]
--loglevel set log level, all possible values are debug, info,
warn and error [default: "info"]
--help Show help [boolean]
--gas gas use to call contract [number]
Error: fail to removeUTXOs: exception with Revert and message Not an admin
at /root/nutWorkspace/firovm-tool/build/MinerContract.js:143:19
at Generator.next (<anonymous>)
at fulfilled (/root/nutWorkspace/firovm-tool/build/MinerContract.js:5:58)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
```
- transaction is reverted with message Not an admin.
- the state remains unchanged. (utxos still same)
<!-- - using the original address that not have any role, by create address such like admin3 -->
#### 2.2.2 Failed: Remove UTXO, Voter is Governance Role
```
node ./build/index.js testing:removeutxo:fail:governance
```
This script will
- run `getnewaddress` to generate 2 user
- user1: call `addMinerForTest` to add user to miner and return utxo
- user2: call `addAddressProposal` to add user to Governance role
- call `callRemoveUTXOs` to remove utxo that return from addMinerForTest. From the user who is Governance role (user2)
<!-- - using the Governance role, by create address such like admin3 and admin3 to the Governance role -->
**Result**:
```bash=
[INFO] admin1 = TSTtgUx6bBraEKxR8QuCiCffQAYZpAmS5Y, admin2 = TXXW8NbMJ5V8afSzgaCSiignHCzieHg72W
[INFO] - proposeMiner:
[INFO] - proposalId: eeabc0aa7c92043324f0f9785c6ce0734b91bf6c3d416e766527f88592ff5046, txid = f33460b757d80509e88f0e09d5e9bebcd6fa273c852d93a473ad17bc90cdb0d8
[INFO] - vote: success
[INFO] - txid: b1b446ca467ff965c30adab4c6abc95da3d1cd01632465f07322f9ed45aecf49
[INFO] - txid=00fb5934295b5d430206ffba55f62966d6a5552ee551b954d2026e4ef085afc5
[INFO] - callRemoveUTXOs:
[INFO] - to contract: 0000000000000000000000000000000000000880
[INFO] - gas: 1000000
[INFO] - with caller: TVwFFz6rgquR2NHTceqNHoUvmfnkjixmvs
index.js test:removeutxo:fail:notgovernance [<gas>]
Test fail with caller who is gov ==> result: message Not an admin
Options:
--version Show version number [boolean]
-e, --env environment variable file location [default: ".env"]
--ignoreerr ignore error while execute [default: false]
--loglevel set log level, all possible values are debug, info,
warn and error [default: "info"]
--help Show help [boolean]
--gas gas use to call contract [number]
Error: fail to removeUTXOs: exception with Revert and message Not an admin
at /root/nutWorkspace/firovm-tool/build/MinerContract.js:143:19
at Generator.next (<anonymous>)
at fulfilled (/root/nutWorkspace/firovm-tool/build/MinerContract.js:5:58)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
```
- transaction is reverted with message Not an admin.
- the state remains unchanged. (utxos still same)
### 2.3 Failed: Remove UTXO, UTXO Not Found
```
node ./build/index.js testing:removeutxo:fail:wrongutxo
```
This script will
- run `getnewaddress` to generate 1 user
- call `addMinerForTest` to add user to miner and return utxo
- Call `ensureAdmin` to be a caller
- Call `callremoveUtxo` function with UTXOs that are not associated with the miner. (wrong utxos)
<!-- **Setup**:
- set up the miner with some UTXOs. By doing the 3.2 in the guide
- Set the sender as an admin.
- Call the `removeUTXOs` function with UTXOs that are not associated with the miner. (wrong utxos) -->
**Result**:
```bash=
[INFO] admin1 = TSTtgUx6bBraEKxR8QuCiCffQAYZpAmS5Y, admin2 = TXXW8NbMJ5V8afSzgaCSiignHCzieHg72W
[INFO] - proposeMiner:
[INFO] - proposalId: ae72e85b5971f37066d1459befa40c2b4362c094696a53ed96e771bb54d46e35, txid = a697c11edd27245ceaf8e4b3cf70b0f940187725e5f8622abea6df812811dabe
[INFO] - vote: success
[INFO] - txid: 752575b28cbfafe972fab074c8bfaeb103b86f1ff0b87140b744bb81666e3dac
[INFO] - callRemoveUTXOs:
[INFO] - to contract: 0000000000000000000000000000000000000880
[INFO] - gas: 1000000
[INFO] - with caller: TSTtgUx6bBraEKxR8QuCiCffQAYZpAmS5Y
index.js test:removeutxo:fail:wrongutxo [<gas>]
Test fail with wrong utxo ==> message utxo is not fount
Options:
--version Show version number [boolean]
-e, --env environment variable file location [default: ".env"]
--ignoreerr ignore error while execute [default: false]
--loglevel set log level, all possible values are debug, info,
warn and error [default: "info"]
--help Show help [boolean]
--gas gas use to call contract [number]
Error: fail to removeUTXOs: exception with Revert and message utxo is not found
at /root/nutWorkspace/firovm-tool/build/MinerContract.js:143:19
at Generator.next (<anonymous>)
at fulfilled (/root/nutWorkspace/firovm-tool/build/MinerContract.js:5:58)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
```
- transaction is reverted with message utxo not found.
## **3. Mining pattern**
### **3.1 Setup Wallet and Contract:**
Initialize everything using this command:
```bash!
node ./build/index.js init --all
```
### **3.2 Create miners list:**
It's up to your environment's setup , in this test.
- have 5 container names `firovm1` , `firovm2` , `firovm3` , `firovm4` , `firovm5` , respectively.
- want to generate 10 miner in each container.
So this is the code.
```shell!=
miners=10 # number of miner addresses
wallet_name="" # name of the wallet to be created
containers=("firovm1" "firovm2" "firovm3" "firovm4" "firovm5")
for container in "${containers[@]}"
do
# Create a new wallet with the specified name
docker exec -it $container firovm-cli --conf=/firovm/firovm.conf createwallet "$wallet_name"
for i in $(seq 1 $miners)
do
# Get a new address from the wallet and write to the miners.txt file
docker exec -it $container firovm-cli --conf=/firovm/firovm.conf getnewaddress 'miner' >> miners.txt
done
done
```
After adding and running this shellscript, we're going to have a `miners.txt` file. which contain the miner address that we just generated.
```bash!=
[miners.txt]
TSZxBzzYK3XFUV56b1bnLwVhEgE4GNgEEU
TVmbNG5qFXGgZToY2Mv3XQegtsMTBZ2QKG
TCbmZVtarSzLNaLcwusTjxYb7HsxKTChvZ
TXUoSK6zmFxfywuiy5LKnRAdwTirb9MAJH
...
...
...
TGxnbRPpHWeoRs194ru5iuTBFyWWT4FiVA
TKAfedY1U5s78VwAThKdKZWQtqXYRHR6po
TFtEFGQs6fhHpPd7wqiYNWiStPQXcxu579
TSFTcVAovgSyCW7XxTHNk4fxz9wzz2yQx8
TXMUVTUH9gAtc2JTQN5WwA97nu8nu5QtAU
```
### **3.3 Add miners:**
Next, we're going to copy the address in miners.txt` to minerlist.txt` in firovm-tool`
```bash!=
|-firovm-tool
|-minerlist.txt
```
After that, build the typescript by using this `tsc`. and run this command.
```bash!=
node .\build\index.js testing:addminers
```
This script is going to read the miners addresses from minerlist.txt` and add them using `addminer`. This addminers accept parameter
- `-u` : which is the number of UTXOs that we want to give to all addresses (`default=200`)
- `-f` : funder (`default=admin1`)
After adding all addresses, it's going to return
```bash!=
[INFO] - add funded
[INFO] Successfully added miner: TFKYdy8ScJxVT6ateJSNRMUqhnYrhb8ayo
[INFO] Adding miner: THfkWx6uQgvPH3gRjocEwPcCgPBZjj66pH
[INFO] admin1 = TH77TQpMjBhcWLNdT1CTPfuqSB1KUXpmUV, admin2 = TH92svMmrpsWZsQ8ihmnPgPnPBwaiNFyfe
[INFO] - proposeMiner:
[INFO] - proposalId: bef25ed212e30da2b08df5874155d1c2c3a7b0ae8974a0d8dc2b5600108fadfc, txid = cca85bb230cb88ea951fec876a2efe32c4d14db2b78ea6f083107b3cabec4a6e
[INFO] - vote: success
[INFO] - txid: 622fb6856b3fe21c9d00a0c21b1e1a125b857914348b346543752192a739cfb1
[INFO] - add funded
[INFO] Successfully added miner: THfkWx6uQgvPH3gRjocEwPcCgPBZjj66pH // This is last address in the list
[INFO] Done adding all miners.
```
### **3.4 Generate blocks:**
We're going to go to the next step, which is using `ensureblock` to generate blocks for the LastPoW.
In this term, our last PoW block is `40320`. So we're going to use `40320` as the parameter.
```bash!=
node .\build\index.js ensureblock 40320
```
waiting for the block to generate to 40320. This process takes time, so please wait.
If it succeeds, you can see this result.
```bash!=
[INFO] ensure block done
[INFO] Complete ensure block 40320
```
After this, the PoA will start very soon. Take your time.
### **3.5 Checking:**
After running PoA for a while, you can check the stats to see how many blocks that address generates by running this command.
```bash!=
node ./build/index.js testing:checkblocks <start> <end>
e.g.
node ./build/index.js testing:checkblocks 40321 41320
// check 1000 block after enter PoA
```
- `<start>` : is the starting number block to check; it has to be more than the LastPoWBlock in this term, which is 40320.
- `<end>` : is the last block to check.
**This is the log when it's checking the block**
```bash!=
...
blockNumber: 41309 || minerAddress: TYGKHgPBRj8dr6j4zwZoRLQYpyFiLqQ3wz
blockNumber: 41310 || minerAddress: TDc5SaSEGXdwi7K84qYVp51fSyu8zcoTLB
blockNumber: 41311 || minerAddress: TW6VnNwodFW382Krtv61sZyoVPBaUW1n2a
blockNumber: 41312 || minerAddress: THfjBo4ghKb6Xsu31LtdBTUw2KN6nATrWL
blockNumber: 41313 || minerAddress: TKmunoenVHnFgJVg6E2gg1qQwHYFCT1eBS
blockNumber: 41314 || minerAddress: TQX14v5dkrSurGEy29XdLmbvSUUmtt4Mjk
blockNumber: 41315 || minerAddress: TQX14v5dkrSurGEy29XdLmbvSUUmtt4Mjk
blockNumber: 41316 || minerAddress: TAX15kPk7ChkFFecH2RyXqdBapZ2zvZeP3
blockNumber: 41317 || minerAddress: TKmunoenVHnFgJVg6E2gg1qQwHYFCT1eBS
blockNumber: 41318 || minerAddress: TEUbSUUbkL8EsdZxcEEhxaKQr3hLYoAusG
blockNumber: 41319 || minerAddress: TAWLqqckvVMcVRvFk6aynpvzAHq3sSJAgE
blockNumber: 41320 || minerAddress: TGTTjKLNDCubBeUzLtxBAuwXbBaZocMwT8
```
From the log, it shows the block number and address that generated the block.
After the process ends, it's going to print like this:
```
...
Check process is complete , Please check the .csv file for details
```
when you reach this step. You can find `blockInfo` and `minerCounts` in the `.txt` and the `.csv` that save the result.
```bash!=
|-firovm-tool
|-blockDifficulty.csv //contain each block difficulty
|-blockInfo.csv //contain what address generate that block
|-blockTime.csv //contain compare block time with previous block
|-minerCounts.csv //contain count of address that generate block
```
In minerCounts.csv you can find something like this. You can use it for static purposes.
```bash!=
Address,Count
TQX14v5dkrSurGEy29XdLmbvSUUmtt4Mjk,40
TDc5SaSEGXdwi7K84qYVp51fSyu8zcoTLB,26
TLun2CGH4bunNRynMk6eW3ruP6sBBfTPVR,17
THmmyMD4DPpHejSyobFojJ629sUM4rePfi,11
...
TTJPo881FigeFJmZf3HcSoVJu1MQzXAAbm,0
TSKSyxY5B3DQZA99rDSxeXsG7yUdvnfkFf,0
TSHcRFvgWbrxyZ2TC1Vh3A5143i5jrm6y2,0
TFKYdy8ScJxVT6ateJSNRMUqhnYrhb8ayo,0
THfkWx6uQgvPH3gRjocEwPcCgPBZjj66pH,0
```
## 4. Test Case: Mint supply case Failed (vote score 2/3)
### Prepare
::: warning
Most of the case below using the `proposalId` to execute later.
**so please note it somewhere.**
:::
::: info
in this case we suggest that you should working on `regtest` , mintsupply proposal can excute after 240 blocks. that will wasting your time.
:::
**setup wallet :**
```
node ./build/index.js testing:init --wallet
```
**setup govcontracts :**
```
node ./build/index.js testing:init --govcontracts
```
### 4.1 Failed - Proposer is not an admin or gov
```
node ./build/index.js testing:mintsupply:guestpropose <block number> <addresses>
eg.
node ./build/index.js testing:mintsupply:guestpropose 1600 'TDeJL2isCeVdy67c6A9wan4gcttQyHxoCe=1001&TFupJ62h9xWntC7SBHmQ6ErJYdpTVy9No5=201'
```
this script will:
- Call `getnewaddress` to generate 1 user.
- Call `propose` on SupplyControl contract to propose new minting by user.
Then `Error` will printed out:
```
Error: fail to propose mint supply: exception with Revert and message Only admin can access
```
You can use this script instead to propose by any address:
```
node ./build/index.js testing:mintsupply:by <proposer addr> <block number> <addresses>'
```
### 4.2 Failed - Proposal expires without enough votes
**Setup**:
- Propose new minting without any vote.
```
node ./build/index.js testing:mintsupply:novote <block number> <addresses>
eg.
node ./build/index.js testing:mintsupply:novote 1601 'TDeJL2isCeVdy67c6A9wan4gcttQyHxoCe=1001'
```
- Then `proposalId` will be printed out.
- We keep this `proposalId` to execute soon.
### 4.3 Failed - Voter votes "ไม่รับ" (against or reject)
**Setup**:
- Propose new minting without any vote.
```
node ./build/index.js testing:mintsupply:novote <block number> <addresses>
```
- Then `proposalId` will be printed out.
- Cast more than 1/3 of the votes against (vote=2) the proposal.
```
node ./build/index.js testing:mintsupply:vote <voters> <vote> <proposalId>
eg.
node ./build/index.js testing:mintsupply:vote 'TFupJ62h9xWntC7SBHmQ6ErJYdpTVy9No5&TWdiSt2fPrtprv8AfsrvCTTV43hYWoCdrk' 2 '73eb573a1f36b205ee88a6c58cc688ab3d2890d913b83a4c4202c938987af5cc'
```
- We keep this `proposalId` to execute soon.
### 4.4 Failed - Voter is not admin or gov
```
node ./build/index.js testing:mintsupply:guestvote <proposalId>
```
This script will
- Call `getnewaddress` to generate 1 user.
- Call `castVote` on SupplyControl contract to vote for support the proposal.
Then Error will printed out:
```
Error: fail to castVote mint supply: exception with Revert and message no vote right
```
### 4.5 Failed - Voter votes "ไม่ลงคะแนน" (abstain)
**Setup**:
- Propose new minting without any vote.
```
node ./build/index.js testing:mintsupply:novote <block number> <addresses>
```
- Then `proposalId` will be printed out.
- Cast more than 1/3 of the votes as abstain (vote = 0).
```
node ./build/index.js testing:mintsupply:vote <voters> 0 <proposalId>
```
- We keep this `proposalId` to execute soon.
### Execute
After we got `proposalId` from (4.2), (4.3) and (4.5), we ensure block passed > 240 blocks. (current block + (>240))
```
node ./build/index.js ensureblock 1550
```
Then, execute each proposal.
```
node ./build/index.js testing:mintsupply:execute <proposalId>
eg.
node ./build/index.js testing:mintsupply:execute <proposalId 4.2>
node ./build/index.js testing:mintsupply:execute <proposalId 4.3>
node ./build/index.js testing:mintsupply:execute <proposalId 4.5>
```
Result:
- From 4.2 (Without any vote)
```
Error: fail to exec mint supply: exception with Revert and message Proposal is not successed
```
- From 4.3 (Cast more than 1/3 of the votes as reject)
```
Error: fail to exec mint supply: exception with Revert and message Proposal is not successed
```
- From 4.5 (Cast more than 1/3 of the votes as abstain)
```
Error: fail to exec mint supply: exception with Revert and message Proposal is not successed
```
### 4.6 Test Case: Proposing a Mint with Past Block Number
```
node ./build/index.js testing:mintsupply:novote <block> <addresses>
eg.
node ./build/index.js testing:mintsupply:novote 100 'TDPKsdpuM3YeH3JnJxe494gJaBZpgv2FPH=1001'
```
Then `Error` will printed out:
```
Error: fail to propose mint supply: exception with Revert and message block number is already pass
```
## 5. Test Case: Burning Supply (Success and Failed)
### Prepare
**setup wallet :**
```
node ./build/index.js testing:init --wallet
```
**setup govcontracts :**
```
node ./build/index.js testing:init --govcontracts
```
### 5.1 Success - Burning supply
```
node ./build/index.js testing:burningsupply:success
```
**Setup**:
- let admin or governance role to be the caller.
- Propose a mint and successfully execute it to add supply to a specific address.
- Define the amount to be burned.
- transfer the defined amount to the zero address.
**Result**:
- the balance of the beneficiary address has decreased by the defined amount.
- the total supply of the token shall decreased by the defined amount.
**Pattern:**
- This below snippet is logs after executed command
(Before run this test, Should re-beginning setup)
```bash=
[INFO] *** before burning process ****
source balance (readable) = 16997.18873997
destination balance (readable) = 0
[INFO] ensure block done
[INFO] Complete ensure block 2109
[INFO] *** after burning process ***
source balance (readable) = 16897.18783996
destiantion balance (readable) = 100
```
### 5.2 Failed - Burning more than available balance
```
node ./build/index.js testing:burningsupply:fail
```
This script will
- call `ensureAdmin`
- call `getaddressbalance` to get balance of admin1
- call `sendtoaddress` to send addressZero and sender is admin1 with value that greater than the beneficiary's balance
<!-- **Setup**:
- let admin or governance role to the caller.
- Propose a mint and successfully execute it to add supply to a specific address.
- Define a burn amount greater than the beneficiary's balance.
- Attempt to burn the defined amount. -->
**Result**:
```bash=
index.js testing:burningsupply:fail
Test fail,value > balance ==> Insufficient funds
Options:
--version Show version number [boolean]
-e, --env environment variable file location [default: ".env"]
--ignoreerr ignore error while execute [default: false]
--loglevel set log level, all possible values are debug, info,
warn and error [default: "info"]
--help Show help [boolean]
RPCError: Insufficient funds
at Client.<anonymous> (/root/nutWorkspace/firovm-tool/build/client/baseRPC.js:61:27)
at Generator.throw (<anonymous>)
at rejected (/root/nutWorkspace/firovm-tool/build/client/baseRPC.js:6:65)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5) {
code: -6,
method: 'sendtoaddress',
params: [
'T9yD14Nj9j7xAB4dbGeiX9h8unkKHxuWwb',
20100,
'',
'',
false,
true,
undefined,
'unset',
false,
undefined,
false,
'TNEKp8XVdH9aDL57nBndJKZvjBx8KWYBdb',
true
]
}
```
- the transaction reverts due to insufficient balance.