(t *testing.T)
| 163 | } |
| 164 | |
| 165 | func TestJoinRNodeAndQuitRNode(t *testing.T) { |
| 166 | // deploy contract |
| 167 | contractBackend := backends.NewDporSimulatedBackend(core.GenesisAlloc{ |
| 168 | ownerAddr: {Balance: big.NewInt(1000000000000)}, |
| 169 | candidateAddr: {Balance: new(big.Int).Mul(big.NewInt(1000000), big.NewInt(configs.Cpc))}, |
| 170 | candidate2Addr: {Balance: new(big.Int).Mul(big.NewInt(1000000), big.NewInt(configs.Cpc))}}) |
| 171 | _, instance := deploy(ownerKey, contractBackend) |
| 172 | |
| 173 | // join rnode |
| 174 | candidateTransactOpts := bind.NewKeyedTransactor(candidateKey) |
| 175 | candidateInvest := new(big.Int).Mul(big.NewInt(200000), big.NewInt(1e+18)) |
| 176 | candidateTransactOpts.GasLimit = uint64(50000000) |
| 177 | candidateTransactOpts.Value = candidateInvest |
| 178 | _, err := instance.JoinRnode(candidateTransactOpts, initVersion) |
| 179 | checkError(t, "join rnode", err) |
| 180 | |
| 181 | contractBackend.Commit() |
| 182 | |
| 183 | checkIsRNode(t, instance, candidateAddr, true) |
| 184 | |
| 185 | checkRNodeNum(t, instance, 1) |
| 186 | |
| 187 | // set period = 0 |
| 188 | ownerTransactOpts := bind.NewKeyedTransactor(ownerKey) |
| 189 | ownerInvest := new(big.Int).Mul(big.NewInt(0), big.NewInt(1e+18)) |
| 190 | ownerTransactOpts.GasLimit = uint64(50000000) |
| 191 | ownerTransactOpts.Value = ownerInvest |
| 192 | _, err = instance.SetPeriod(ownerTransactOpts, new(big.Int).SetInt64(0)) |
| 193 | |
| 194 | contractBackend.Commit() |
| 195 | |
| 196 | // get period |
| 197 | period, err := instance.Period(nil) |
| 198 | if period.Cmp(big.NewInt(0)) != 0 { |
| 199 | t.Fatalf("period is error. %v != %v", period, 0) |
| 200 | } |
| 201 | |
| 202 | // quit rnode |
| 203 | candidateTransactOpts = bind.NewKeyedTransactor(candidateKey) |
| 204 | candidateInvest = new(big.Int).Mul(big.NewInt(0), big.NewInt(1e+18)) |
| 205 | candidateTransactOpts.GasLimit = uint64(50000000) |
| 206 | candidateTransactOpts.Value = candidateInvest |
| 207 | _, err = instance.QuitRnode(candidateTransactOpts) |
| 208 | checkError(t, "quit rnode", err) |
| 209 | |
| 210 | contractBackend.Commit() |
| 211 | |
| 212 | checkIsRNode(t, instance, candidateAddr, false) |
| 213 | |
| 214 | checkRNodeNum(t, instance, 0) |
| 215 | } |
| 216 | |
| 217 | func TestRNodeThreshold(t *testing.T) { |
| 218 | // deploy contract |
nothing calls this directly
no test coverage detected