1515// along with this program. If not, see <https://www.gnu.org/licenses/>.
1616
1717import { expect } from "chai" ;
18- import { U64 } from "codechain-sdk/lib/core/classes" ;
18+ import { PlatformAddress , U64 } from "codechain-sdk/lib/core/classes" ;
1919import "mocha" ;
20- import { aliceAddress , aliceSecret , faucetAddress } from "../helper/constants" ;
20+ import {
21+ aliceAddress ,
22+ aliceSecret ,
23+ bobAddress ,
24+ faucetAddress
25+ } from "../helper/constants" ;
2126import CodeChain from "../helper/spawn" ;
2227
2328describe ( "Reward = 50, 1 miner" , function ( ) {
29+ const MIN_FEE_PAY = 10 ;
30+ const BLOCK_REWARD = 50 ;
31+ const FAUCET_INITIAL_CCS = new U64 ( "18000000000000000000" ) ;
32+
2433 let node : CodeChain ;
2534
2635 beforeEach ( async function ( ) {
@@ -33,15 +42,30 @@ describe("Reward = 50, 1 miner", function() {
3342
3443 it ( "Mining an empty block" , async function ( ) {
3544 await node . sdk . rpc . devel . startSealing ( ) ;
45+ expect (
46+ await node . sdk . rpc . chain . getBalance ( faucetAddress )
47+ ) . to . deep . equal ( FAUCET_INITIAL_CCS ) ;
3648 expect ( await node . sdk . rpc . chain . getBalance ( aliceAddress ) ) . to . deep . equal (
37- new U64 ( 50 )
49+ new U64 ( BLOCK_REWARD )
50+ ) ;
51+ expect ( await node . sdk . rpc . chain . getBalance ( bobAddress ) ) . to . deep . equal (
52+ new U64 ( 0 )
3853 ) ;
3954 } ) ;
4055
4156 it ( "Mining a block with 1 transaction" , async function ( ) {
4257 await node . sendPayTx ( { fee : 10 } ) ;
58+
59+ expect (
60+ await node . sdk . rpc . chain . getBalance ( faucetAddress )
61+ ) . to . deep . equal (
62+ FAUCET_INITIAL_CCS . minus ( 10 /* fee */ ) . plus ( 7 /* share */ )
63+ ) ;
4364 expect ( await node . sdk . rpc . chain . getBalance ( aliceAddress ) ) . to . deep . equal (
44- new U64 ( 50 + 10 )
65+ new U64 ( 2 /* share */ ) . plus ( BLOCK_REWARD )
66+ ) ;
67+ expect ( await node . sdk . rpc . chain . getBalance ( bobAddress ) ) . to . deep . equal (
68+ new U64 ( 1 /* share */ )
4569 ) ;
4670 } ) ;
4771
@@ -60,33 +84,81 @@ describe("Reward = 50, 1 miner", function() {
6084 seq : 2
6185 } ) ;
6286 await node . sdk . rpc . devel . startSealing ( ) ;
87+
88+ expect (
89+ await node . sdk . rpc . chain . getBalance ( faucetAddress )
90+ ) . to . deep . equal (
91+ FAUCET_INITIAL_CCS . minus ( 10 + 10 + 15 /* fee */ ) . plus (
92+ 21 /* share */
93+ )
94+ ) ;
6395 expect ( await node . sdk . rpc . chain . getBalance ( aliceAddress ) ) . to . deep . equal (
64- new U64 ( 50 + 35 )
96+ new U64 ( 6 /* share */ )
97+ . plus ( 10 + 10 + 15 - 3 * MIN_FEE_PAY /* share remaining */ )
98+ . plus ( BLOCK_REWARD )
99+ ) ;
100+ expect ( await node . sdk . rpc . chain . getBalance ( bobAddress ) ) . to . deep . equal (
101+ new U64 ( 3 /* share */ )
65102 ) ;
66103 } ) ;
67104
68105 it ( "Mining a block with a transaction that pays the author" , async function ( ) {
69106 await node . pay ( aliceAddress , 100 ) ;
107+ expect (
108+ await node . sdk . rpc . chain . getBalance ( faucetAddress )
109+ ) . to . deep . equal (
110+ FAUCET_INITIAL_CCS . minus ( 100 /* pay */ )
111+ . minus ( 10 /* fee */ )
112+ . plus ( 7 /* share */ )
113+ ) ;
70114 expect ( await node . sdk . rpc . chain . getBalance ( aliceAddress ) ) . to . deep . equal (
71- new U64 ( 50 + 10 + 100 )
115+ new U64 ( 100 /* pay */ ) . plus ( 2 /* share */ ) . plus ( BLOCK_REWARD )
116+ ) ;
117+ expect ( await node . sdk . rpc . chain . getBalance ( bobAddress ) ) . to . deep . equal (
118+ new U64 ( 1 /* share */ )
72119 ) ;
73120 } ) ;
74121
75122 it ( "Mining a block with a transaction which author pays someone in" , async function ( ) {
76- await node . sendPayTx ( { fee : 10 } ) ; // +60
123+ await node . sendPayTx ( { fee : 10 } ) ;
124+ expect (
125+ await node . sdk . rpc . chain . getBalance ( faucetAddress )
126+ ) . to . deep . equal (
127+ FAUCET_INITIAL_CCS . minus ( 10 /* fee */ ) . plus ( 7 /* share */ )
128+ ) ;
77129 expect ( await node . sdk . rpc . chain . getBalance ( aliceAddress ) ) . to . deep . equal (
78- new U64 ( 60 )
130+ new U64 ( 2 /* share */ ) . plus ( BLOCK_REWARD )
131+ ) ;
132+ expect ( await node . sdk . rpc . chain . getBalance ( bobAddress ) ) . to . deep . equal (
133+ new U64 ( 1 /* share */ )
79134 ) ;
80135
81136 const tx = await node . sdk . core
82137 . createPayTransaction ( {
83138 recipient : faucetAddress ,
84- quantity : 50
139+ quantity : 20
85140 } )
86- . sign ( { secret : aliceSecret , seq : 0 , fee : 10 } ) ; // -60
87- await node . sdk . rpc . chain . sendSignedTransaction ( tx ) ; // +60
141+ . sign ( { secret : aliceSecret , seq : 0 , fee : 10 } ) ;
142+ await node . sdk . rpc . chain . sendSignedTransaction ( tx ) ;
143+
144+ expect (
145+ await node . sdk . rpc . chain . getBalance ( faucetAddress )
146+ ) . to . deep . equal (
147+ FAUCET_INITIAL_CCS . minus ( 10 )
148+ . plus ( 7 )
149+ . plus ( 20 /* pay */ )
150+ . plus ( 7 /* share */ )
151+ ) ;
88152 expect ( await node . sdk . rpc . chain . getBalance ( aliceAddress ) ) . to . deep . equal (
89- new U64 ( 60 )
153+ new U64 ( 2 )
154+ . plus ( BLOCK_REWARD )
155+ . minus ( 20 /* pay */ )
156+ . minus ( 10 /* fee */ )
157+ . plus ( 2 /* share */ )
158+ . plus ( BLOCK_REWARD )
159+ ) ;
160+ expect ( await node . sdk . rpc . chain . getBalance ( bobAddress ) ) . to . deep . equal (
161+ new U64 ( 1 /* share*/ ) . plus ( 1 /* share */ )
90162 ) ;
91163 } ) ;
92164
0 commit comments