(t *testing.T)
| 215 | } |
| 216 | |
| 217 | func TestRNodeThreshold(t *testing.T) { |
| 218 | // deploy contract |
| 219 | contractBackend := backends.NewDporSimulatedBackend(core.GenesisAlloc{ |
| 220 | ownerAddr: {Balance: big.NewInt(1000000000000)}, |
| 221 | candidateAddr: {Balance: new(big.Int).Mul(big.NewInt(1000000), big.NewInt(configs.Cpc))}, |
| 222 | candidate2Addr: {Balance: new(big.Int).Mul(big.NewInt(1000000), big.NewInt(configs.Cpc))}}) |
| 223 | _, instance := deploy(ownerKey, contractBackend) |
| 224 | |
| 225 | // join rnode |
| 226 | candidateTransactOpts := bind.NewKeyedTransactor(candidateKey) |
| 227 | candidateInvest := new(big.Int).Mul(big.NewInt(200000), big.NewInt(1e+18)) |
| 228 | candidateTransactOpts.GasLimit = uint64(50000000) |
| 229 | candidateTransactOpts.Value = candidateInvest |
| 230 | _, err := instance.JoinRnode(candidateTransactOpts, initVersion) |
| 231 | checkError(t, "join rnode", err) |
| 232 | |
| 233 | contractBackend.Commit() |
| 234 | |
| 235 | checkIsRNode(t, instance, candidateAddr, true) |
| 236 | |
| 237 | checkRNodeNum(t, instance, 1) |
| 238 | |
| 239 | // set threshold = 1 |
| 240 | ownerTransactOpts := bind.NewKeyedTransactor(ownerKey) |
| 241 | ownerInvest := new(big.Int).Mul(big.NewInt(0), big.NewInt(1e+18)) |
| 242 | ownerTransactOpts.GasLimit = uint64(50000000) |
| 243 | ownerTransactOpts.Value = ownerInvest |
| 244 | |
| 245 | newThreshold := new(big.Int).Mul(big.NewInt(3000000), big.NewInt(1e+18)) |
| 246 | _, err = instance.SetRnodeThreshold(ownerTransactOpts, newThreshold) |
| 247 | checkError(t, "set rnode threshold", err) |
| 248 | |
| 249 | contractBackend.Commit() |
| 250 | |
| 251 | // get threshold |
| 252 | threshold, err := instance.RnodeThreshold(nil) |
| 253 | checkError(t, "get threshold", err) |
| 254 | if threshold.Cmp(newThreshold) != 0 { |
| 255 | t.Fatalf("threshold error! %d != %d", threshold, newThreshold) |
| 256 | } |
| 257 | |
| 258 | // join rnode |
| 259 | candidate2TransactOpts := bind.NewKeyedTransactor(candidate2Key) |
| 260 | candidate2Invest := new(big.Int).Mul(big.NewInt(200000), big.NewInt(1e+18)) |
| 261 | candidate2TransactOpts.GasLimit = uint64(50000000) |
| 262 | candidate2TransactOpts.Value = candidate2Invest |
| 263 | _, err = instance.JoinRnode(candidate2TransactOpts, initVersion) |
| 264 | checkError(t, "join rnode", err) |
| 265 | |
| 266 | contractBackend.Commit() |
| 267 | |
| 268 | checkIsRNode(t, instance, candidate2Addr, false) |
| 269 | |
| 270 | checkRNodeNum(t, instance, 1) |
| 271 | } |
| 272 | |
| 273 | func TestRNodeEnableAndDisable(t *testing.T) { |
| 274 | // deploy contract |
nothing calls this directly
no test coverage detected