From e0b9dab532bf18a148efe2b63ebf23c54d1b8d20 Mon Sep 17 00:00:00 2001 From: 4000D Date: Tue, 22 Jan 2019 07:00:22 +0900 Subject: [PATCH] pls: fix checkBlock test function --- pls/rootchain_manager_test.go | 229 ++++++++++++++++++---------------- 1 file changed, 118 insertions(+), 111 deletions(-) diff --git a/pls/rootchain_manager_test.go b/pls/rootchain_manager_test.go index 0c06ab176..e1ebc5cd4 100644 --- a/pls/rootchain_manager_test.go +++ b/pls/rootchain_manager_test.go @@ -184,14 +184,14 @@ func TestScenario1(t *testing.T) { blockInfo := ev.Data.(core.NewMinedBlockEvent) if rcm.minerEnv.IsRequest { - t.Fatal("PlasmaBlock should not be request block, but it is not. blockNumber:", blockInfo.Block.NumberU64()) + t.Fatal("Block should not be request block, but it is not. blockNumber:", blockInfo.Block.NumberU64()) } } ev := <-events.Chan() blockInfo := ev.Data.(core.NewMinedBlockEvent) if !rcm.minerEnv.IsRequest { - t.Fatal("PlasmaBlock should be request block", "blockNumber", blockInfo.Block.NumberU64()) + t.Fatal("Block should be request block", "blockNumber", blockInfo.Block.NumberU64()) } for i = 0; i < NRELength.Uint64()*2; { @@ -202,7 +202,7 @@ func TestScenario1(t *testing.T) { makeSampleTx(rcm) if rcm.minerEnv.IsRequest { - t.Fatal("PlasmaBlock should not be request block", "blockNumber", blockInfo.Block.NumberU64()) + t.Fatal("Block should not be request block", "blockNumber", blockInfo.Block.NumberU64()) } } @@ -282,7 +282,7 @@ func TestScenario2(t *testing.T) { blockInfo := ev.Data.(core.NewMinedBlockEvent) if rcm.minerEnv.IsRequest { - t.Fatal("PlasmaBlock should not be request block, but it is not. blockNumber:", blockInfo.Block.NumberU64()) + t.Fatal("Block should not be request block, but it is not. blockNumber:", blockInfo.Block.NumberU64()) } } @@ -292,7 +292,7 @@ func TestScenario2(t *testing.T) { ev := <-events.Chan() blockInfo := ev.Data.(core.NewMinedBlockEvent) if !rcm.minerEnv.IsRequest { - t.Fatal("PlasmaBlock should be request block", "blockNumber", blockInfo.Block.NumberU64()) + t.Fatal("Block should be request block", "blockNumber", blockInfo.Block.NumberU64()) } // balance check in plasma chain after enter db, _ := rcm.blockchain.State() @@ -322,7 +322,7 @@ func TestScenario2(t *testing.T) { makeSampleTx(rcm) if rcm.minerEnv.IsRequest { - t.Fatal("PlasmaBlock should not be request block", "blockNumber", blockInfo.Block.NumberU64()) + t.Fatal("Block should not be request block", "blockNumber", blockInfo.Block.NumberU64()) } } @@ -339,7 +339,7 @@ func TestScenario2(t *testing.T) { ev := <-events.Chan() blockInfo := ev.Data.(core.NewMinedBlockEvent) if !rcm.minerEnv.IsRequest { - t.Fatal("PlasmaBlock should be request block", "blockNumber", blockInfo.Block.NumberU64()) + t.Fatal("Block should be request block", "blockNumber", blockInfo.Block.NumberU64()) } db, _ := rcm.blockchain.State() @@ -358,7 +358,7 @@ func TestScenario2(t *testing.T) { makeSampleTx(rcm) if rcm.minerEnv.IsRequest { - t.Fatal("PlasmaBlock should not be request block", "blockNumber", blockInfo.Block.NumberU64()) + t.Fatal("Block should not be request block", "blockNumber", blockInfo.Block.NumberU64()) } } @@ -420,11 +420,11 @@ func TestScenario3(t *testing.T) { log.Info("All backends are set up") - // NRBEpoch#1 / PlasmaBlock#1 (1/2) + // NRE#1 / Block#1 (1/2) tokenInRootChain, tokenInChildChain, tokenAddrInRootChain, tokenAddrInChildChain := deployTokenContracts(t) wait(4) - if err := checkBlock(pls, plasmaBlockMinedEvents, blockSubmitEvents, false, 0); err != nil { + if err := checkBlock(pls, plasmaBlockMinedEvents, blockSubmitEvents, false, 0, 1); err != nil { t.Fatal(err) } @@ -475,15 +475,15 @@ func TestScenario3(t *testing.T) { startETHDeposit(t, pls.rootchainManager, key, depositAmount) } - // NRBEpoch#1 / PlasmaBlock#2 (2/2) + // NRE#1 / Block#2 (2/2) makeSampleTx(pls.rootchainManager) - if err := checkBlock(pls, plasmaBlockMinedEvents, blockSubmitEvents, false, 0); err != nil { + if err := checkBlock(pls, plasmaBlockMinedEvents, blockSubmitEvents, false, 0, 2); err != nil { t.Fatal(err) } - // ORBEpoch#2 / PlasmaBlock#3 (1/1): 4 ETH deposits - if err := checkBlock(pls, plasmaBlockMinedEvents, blockSubmitEvents, true, 0); err != nil { + // ORE#2 / Block#3 (1/1): 4 ETH deposits + if err := checkBlock(pls, plasmaBlockMinedEvents, blockSubmitEvents, true, 0, 3); err != nil { t.Fatal(err) } @@ -514,22 +514,22 @@ func TestScenario3(t *testing.T) { startTokenDeposit(t, pls.rootchainManager, tokenInRootChain, tokenAddrInRootChain, key1, tokenAmount) //wait(2) - // NRBEpoch#3 / PlasmaBlock#4 (1/2) + // NRE#3 / Block#4 (1/2) makeSampleTx(pls.rootchainManager) - if err := checkBlock(pls, plasmaBlockMinedEvents, blockSubmitEvents, false, 0); err != nil { + if err := checkBlock(pls, plasmaBlockMinedEvents, blockSubmitEvents, false, 0, 4); err != nil { t.Fatal(err) } - // NRBEpoch#3 / PlasmaBlock#5 (2/2) + // NRE#3 / Block#5 (2/2) makeSampleTx(pls.rootchainManager) - if err := checkBlock(pls, plasmaBlockMinedEvents, blockSubmitEvents, false, 0); err != nil { + if err := checkBlock(pls, plasmaBlockMinedEvents, blockSubmitEvents, false, 0, 5); err != nil { t.Fatal(err) } - // ORBEpoch#4 / PlasmaBlock#6 (1/1): 1 Token deposit - if err := checkBlock(pls, plasmaBlockMinedEvents, blockSubmitEvents, true, 0); err != nil { + // ORE#4 / Block#6 (1/1): 1 Token deposit + if err := checkBlock(pls, plasmaBlockMinedEvents, blockSubmitEvents, true, 0, 6); err != nil { t.Fatal(err) } @@ -552,9 +552,9 @@ func TestScenario3(t *testing.T) { tokenAmountToTransfer := new(big.Int).Div(ether(1), big.NewInt(2)) tokenAmountToTransferNeg := new(big.Int).Neg(tokenAmountToTransfer) - // NRBEpoch#5 / PlasmaBlock#7 (1/2) + // NRE#5 / Block#7 (1/2) transferToken(t, tokenInChildChain, key1, addr2, tokenAmountToTransfer) - if err := checkBlock(pls, plasmaBlockMinedEvents, blockSubmitEvents, false, 0); err != nil { + if err := checkBlock(pls, plasmaBlockMinedEvents, blockSubmitEvents, false, 0, 7); err != nil { t.Fatal(err) } @@ -566,10 +566,10 @@ func TestScenario3(t *testing.T) { t.Fatal(err) } - // NRBEpoch#5 / PlasmaBlock#8 (2/2) + // NRE#5 / Block#8 (2/2) transferToken(t, tokenInChildChain, key1, addr2, tokenAmountToTransfer) - if err := checkBlock(pls, plasmaBlockMinedEvents, blockSubmitEvents, false, 0); err != nil { + if err := checkBlock(pls, plasmaBlockMinedEvents, blockSubmitEvents, false, 0, 8); err != nil { t.Fatal(err) } @@ -581,10 +581,10 @@ func TestScenario3(t *testing.T) { t.Fatal(err) } - // NRBEpoch#6 / PlasmaBlock#9 (1/2) + // NRE#6 / Block#9 (1/2) makeSampleTx(pls.rootchainManager) - if err := checkBlock(pls, plasmaBlockMinedEvents, blockSubmitEvents, false, 0); err != nil { + if err := checkBlock(pls, plasmaBlockMinedEvents, blockSubmitEvents, false, 0, 9); err != nil { t.Fatal(err) } @@ -596,15 +596,15 @@ func TestScenario3(t *testing.T) { // (1/4) withdraw addr2's token to root chain startTokenWithdraw(t, pls.rootchainManager.rootchainContract, tokenInRootChain, tokenAddrInRootChain, key2, tokenAmountToWithdraw, big.NewInt(int64(pls.rootchainManager.state.costERO))) - // NRBEpoch#6 / PlasmaBlock#10 (2/2) + // NRE#6 / Block#10 (2/2) makeSampleTx(pls.rootchainManager) - if err := checkBlock(pls, plasmaBlockMinedEvents, blockSubmitEvents, false, 0); err != nil { + if err := checkBlock(pls, plasmaBlockMinedEvents, blockSubmitEvents, false, 0, 10); err != nil { t.Fatal(err) } - // ORBEpoch#7 / PlasmaBlock#11 (1/1) + // ORE#7 / Block#11 (1/1) makeSampleTx(pls.rootchainManager) - if err := checkBlock(pls, plasmaBlockMinedEvents, blockSubmitEvents, true, 0); err != nil { + if err := checkBlock(pls, plasmaBlockMinedEvents, blockSubmitEvents, true, 0, 11); err != nil { t.Fatal(err) } @@ -613,23 +613,23 @@ func TestScenario3(t *testing.T) { t.Fatal(err) } - // NRBEpoch#8 / PlasmaBlock#12 (1/2) + // NRE#8 / Block#12 (1/2) makeSampleTx(pls.rootchainManager) - if err := checkBlock(pls, plasmaBlockMinedEvents, blockSubmitEvents, false, 0); err != nil { + if err := checkBlock(pls, plasmaBlockMinedEvents, blockSubmitEvents, false, 0, 12); err != nil { t.Fatal(err) } // (2/4) withdraw addr2's token to root chain startTokenWithdraw(t, pls.rootchainManager.rootchainContract, tokenInRootChain, tokenAddrInRootChain, key2, tokenAmountToWithdraw, big.NewInt(int64(pls.rootchainManager.state.costERO))) - // NRBEpoch#8 / PlasmaBlock#13 (2/2) + // NRE#8 / Block#13 (2/2) makeSampleTx(pls.rootchainManager) - if err := checkBlock(pls, plasmaBlockMinedEvents, blockSubmitEvents, false, 0); err != nil { + if err := checkBlock(pls, plasmaBlockMinedEvents, blockSubmitEvents, false, 0, 13); err != nil { t.Fatal(err) } - // ORBEpoch#9 / PlasmaBlock#14 (1/1) - if err := checkBlock(pls, plasmaBlockMinedEvents, blockSubmitEvents, true, 0); err != nil { + // ORE#9 / Block#14 (1/1) + if err := checkBlock(pls, plasmaBlockMinedEvents, blockSubmitEvents, true, 0, 14); err != nil { t.Fatal(err) } @@ -638,23 +638,23 @@ func TestScenario3(t *testing.T) { t.Fatal(err) } - // NRBEpoch#10 / PlasmaBlock#15 (1/2) + // NRE#10 / Block#15 (1/2) makeSampleTx(pls.rootchainManager) - if err := checkBlock(pls, plasmaBlockMinedEvents, blockSubmitEvents, false, 0); err != nil { + if err := checkBlock(pls, plasmaBlockMinedEvents, blockSubmitEvents, false, 0, 15); err != nil { t.Fatal(err) } // (3/4) withdraw addr2's token to root chain startTokenWithdraw(t, pls.rootchainManager.rootchainContract, tokenInRootChain, tokenAddrInRootChain, key2, tokenAmountToWithdraw, big.NewInt(int64(pls.rootchainManager.state.costERO))) - // NRBEpoch#10 / PlasmaBlock#16 (2/2) + // NRE#10 / Block#16 (2/2) makeSampleTx(pls.rootchainManager) - if err := checkBlock(pls, plasmaBlockMinedEvents, blockSubmitEvents, false, 0); err != nil { + if err := checkBlock(pls, plasmaBlockMinedEvents, blockSubmitEvents, false, 0, 16); err != nil { t.Fatal(err) } - // ORBEpoch#11 / PlasmaBlock#17 (1/1) - if err := checkBlock(pls, plasmaBlockMinedEvents, blockSubmitEvents, true, 0); err != nil { + // ORE#11 / Block#17 (1/1) + if err := checkBlock(pls, plasmaBlockMinedEvents, blockSubmitEvents, true, 0, 17); err != nil { t.Fatal(err) } @@ -663,23 +663,23 @@ func TestScenario3(t *testing.T) { t.Fatal(err) } - // NRBEpoch#12 / PlasmaBlock#18 (1/2) + // NRE#12 / Block#18 (1/2) makeSampleTx(pls.rootchainManager) - if err := checkBlock(pls, plasmaBlockMinedEvents, blockSubmitEvents, false, 0); err != nil { + if err := checkBlock(pls, plasmaBlockMinedEvents, blockSubmitEvents, false, 0, 18); err != nil { t.Fatal(err) } // (4/4) withdraw addr2's token to root chain startTokenWithdraw(t, pls.rootchainManager.rootchainContract, tokenInRootChain, tokenAddrInRootChain, key2, tokenAmountToWithdraw, big.NewInt(int64(pls.rootchainManager.state.costERO))) - // NRBEpoch#12 / PlasmaBlock#19 (2/2) + // NRE#12 / Block#19 (2/2) makeSampleTx(pls.rootchainManager) - if err := checkBlock(pls, plasmaBlockMinedEvents, blockSubmitEvents, false, 0); err != nil { + if err := checkBlock(pls, plasmaBlockMinedEvents, blockSubmitEvents, false, 0, 19); err != nil { t.Fatal(err) } - // ORBEpoch#13 / PlasmaBlock#20 (1/1) - if err := checkBlock(pls, plasmaBlockMinedEvents, blockSubmitEvents, true, 0); err != nil { + // ORE#13 / Block#20 (1/1) + if err := checkBlock(pls, plasmaBlockMinedEvents, blockSubmitEvents, true, 0, 20); err != nil { t.Fatal(err) } @@ -688,15 +688,15 @@ func TestScenario3(t *testing.T) { t.Fatal(err) } - // NRBEpoch#14 / PlasmaBlock#21 (1/2) + // NRE#14 / Block#21 (1/2) makeSampleTx(pls.rootchainManager) - if err := checkBlock(pls, plasmaBlockMinedEvents, blockSubmitEvents, false, 0); err != nil { + if err := checkBlock(pls, plasmaBlockMinedEvents, blockSubmitEvents, false, 0, 21); err != nil { t.Fatal(err) } - // NRBEpoch#14 / PlasmaBlock#22 (2/2) + // NRE#14 / Block#22 (2/2) makeSampleTx(pls.rootchainManager) - if err := checkBlock(pls, plasmaBlockMinedEvents, blockSubmitEvents, false, 0); err != nil { + if err := checkBlock(pls, plasmaBlockMinedEvents, blockSubmitEvents, false, 0, 22); err != nil { t.Fatal(err) } @@ -757,11 +757,11 @@ func TestScenario4(t *testing.T) { log.Info("All backends are set up") - // NRBEpoch#1 / PlasmaBlock#1 (1/2) + // NRE#1 / Block#1 (1/2) tokenInRootChain, tokenInChildChain, tokenAddrInRootChain, tokenAddrInChildChain := deployTokenContracts(t) wait(4) - if err := checkBlock(pls, plasmaBlockMinedEvents, blockSubmitEvents, false, 0); err != nil { + if err := checkBlock(pls, plasmaBlockMinedEvents, blockSubmitEvents, false, 0, 1); err != nil { t.Fatal(err) } @@ -812,15 +812,15 @@ func TestScenario4(t *testing.T) { startETHDeposit(t, pls.rootchainManager, key, depositAmount) } - // NRBEpoch#1 / PlasmaBlock#2 (2/2) + // NRE#1 / Block#2 (2/2) makeSampleTx(pls.rootchainManager) - if err := checkBlock(pls, plasmaBlockMinedEvents, blockSubmitEvents, false, 0); err != nil { + if err := checkBlock(pls, plasmaBlockMinedEvents, blockSubmitEvents, false, 0, 2); err != nil { t.Fatal(err) } - // ORBEpoch#2 / PlasmaBlock#3 (1/1): 4 ETH deposits - if err := checkBlock(pls, plasmaBlockMinedEvents, blockSubmitEvents, true, 0); err != nil { + // ORE#2 / Block#3 (1/1): 4 ETH deposits + if err := checkBlock(pls, plasmaBlockMinedEvents, blockSubmitEvents, true, 0, 3); err != nil { t.Fatal(err) } @@ -851,22 +851,22 @@ func TestScenario4(t *testing.T) { startTokenDeposit(t, pls.rootchainManager, tokenInRootChain, tokenAddrInRootChain, key1, tokenAmount) wait(2) - // NRBEpoch#3 / PlasmaBlock#4 (1/2) + // NRE#3 / Block#4 (1/2) makeSampleTx(pls.rootchainManager) - if err := checkBlock(pls, plasmaBlockMinedEvents, blockSubmitEvents, false, 0); err != nil { + if err := checkBlock(pls, plasmaBlockMinedEvents, blockSubmitEvents, false, 0, 4); err != nil { t.Fatal(err) } - // NRBEpoch#3 / PlasmaBlock#5 (2/2) + // NRE#3 / Block#5 (2/2) makeSampleTx(pls.rootchainManager) - if err := checkBlock(pls, plasmaBlockMinedEvents, blockSubmitEvents, false, 0); err != nil { + if err := checkBlock(pls, plasmaBlockMinedEvents, blockSubmitEvents, false, 0, 5); err != nil { t.Fatal(err) } - // ORBEpoch#4 / PlasmaBlock#6 (1/1): 1 Token deposit - if err := checkBlock(pls, plasmaBlockMinedEvents, blockSubmitEvents, true, 0); err != nil { + // ORE#4 / Block#6 (1/1): 1 Token deposit + if err := checkBlock(pls, plasmaBlockMinedEvents, blockSubmitEvents, true, 0, 6); err != nil { t.Fatal(err) } @@ -888,51 +888,51 @@ func TestScenario4(t *testing.T) { wait(2) - // NRBEpoch#5 / PlasmaBlock#7 (1/2) + // NRE#5 / Block#7 (1/2) makeSampleTx(pls.rootchainManager) - if err := checkBlock(pls, plasmaBlockMinedEvents, blockSubmitEvents, false, 0); err != nil { + if err := checkBlock(pls, plasmaBlockMinedEvents, blockSubmitEvents, false, 0, 7); err != nil { t.Fatal(err) } - // NRBEpoch#5 / PlasmaBlock#8 (2/2) + // NRE#5 / Block#8 (2/2) makeSampleTx(pls.rootchainManager) - if err := checkBlock(pls, plasmaBlockMinedEvents, blockSubmitEvents, false, 0); err != nil { + if err := checkBlock(pls, plasmaBlockMinedEvents, blockSubmitEvents, false, 0, 8); err != nil { t.Fatal(err) } - // ORBEpoch#6 / PlasmaBlock#9 (1/1): invalid withdrawal + // ORE#6 / Block#9 (1/1): invalid withdrawal - if err := checkBlock(pls, plasmaBlockMinedEvents, blockSubmitEvents, true, 0); err != nil { + if err := checkBlock(pls, plasmaBlockMinedEvents, blockSubmitEvents, true, 0, 9); err != nil { t.Fatal(err) } - // NRBEpoch#7 / PlasmaBlock#10 (1/2) + // NRE#7 / Block#10 (1/2) makeSampleTx(pls.rootchainManager) - if err := checkBlock(pls, plasmaBlockMinedEvents, blockSubmitEvents, false, 0); err != nil { + if err := checkBlock(pls, plasmaBlockMinedEvents, blockSubmitEvents, false, 0, 10); err != nil { t.Fatal(err) } - // NRBEpoch#7 / PlasmaBlock#11 (2/2) + // NRE#7 / Block#11 (2/2) makeSampleTx(pls.rootchainManager) - if err := checkBlock(pls, plasmaBlockMinedEvents, blockSubmitEvents, false, 0); err != nil { + if err := checkBlock(pls, plasmaBlockMinedEvents, blockSubmitEvents, false, 0, 11); err != nil { t.Fatal(err) } - // NRBEpoch#8 / PlasmaBlock#12 (1/2) + // NRE#8 / Block#12 (1/2) makeSampleTx(pls.rootchainManager) - if err := checkBlock(pls, plasmaBlockMinedEvents, blockSubmitEvents, false, 0); err != nil { + if err := checkBlock(pls, plasmaBlockMinedEvents, blockSubmitEvents, false, 0, 12); err != nil { t.Fatal(err) } - // NRBEpoch#8 / PlasmaBlock#12 (2/2) + // NRE#8 / Block#13 (2/2) makeSampleTx(pls.rootchainManager) - if err := checkBlock(pls, plasmaBlockMinedEvents, blockSubmitEvents, false, 0); err != nil { + if err := checkBlock(pls, plasmaBlockMinedEvents, blockSubmitEvents, false, 0, 13); err != nil { t.Fatal(err) } @@ -950,8 +950,9 @@ func TestScenario4(t *testing.T) { applyRequests(t, pls.rootchainManager.rootchainContract, operatorKey) } -// NRB#1 - NRB#2 - (ORB#3) - NRB#3 - NRB#4 - ORB#5 - NRB#6 - NRB#7 - ORB#8 -// ㄴ URB#7 - (ORB#8(#8')) - NRB#8(#7') +// NRB#1 - NRB#2 - (no ORB) - NRB#3 - NRB#4 - ORB#5 - NRB#6 - NRB#7 - ORB#8 +// ㄴ URB#7 - (ORB#8(#8')) - NRB#8(#7') +// TODO: test enter is rebased func TestScenario5(t *testing.T) { pls, rpcServer, dir, err := makePls() defer os.RemoveAll(dir) @@ -991,8 +992,8 @@ func TestScenario5(t *testing.T) { tokenInRootChain, tokenInChildChain, tokenAddrInRootChain, tokenAddrInChildChain := deployTokenContracts(t) - // NRBEpoch#0.1 / PlasmaBlock#0.1 (1/2) - if err := checkBlock(pls, plasmaBlockMinedEvents, blockSubmitEvents, false, 0); err != nil { + // NRE#0.1 / Block#0.1 (1/2) + if err := checkBlock(pls, plasmaBlockMinedEvents, blockSubmitEvents, false, 0, 1); err != nil { t.Fatal(err) } @@ -1032,10 +1033,10 @@ func TestScenario5(t *testing.T) { t.Fatalf("RootChain doesn't know requestable contract address in child chain: %v != %v", tokenAddrInChildChain, tokenAddr) } - // NRBEpoch#0.1 / PlasmaBlock#0.2 (2/2) + // NRE#0.1 / Block#0.2 (2/2) makeSampleTx(pls.rootchainManager) - if err := checkBlock(pls, plasmaBlockMinedEvents, blockSubmitEvents, false, 0); err != nil { + if err := checkBlock(pls, plasmaBlockMinedEvents, blockSubmitEvents, false, 0, 2); err != nil { t.Fatal(err) } @@ -1059,22 +1060,22 @@ func TestScenario5(t *testing.T) { startTokenDeposit(t, pls.rootchainManager, tokenInRootChain, tokenAddrInRootChain, key1, tokenAmount) - // NRBEpoch#0.3 / PlasmaBlock#0.3 (1/2) + // NRE#0.3 / Block#0.3 (1/2) makeSampleTx(pls.rootchainManager) - if err := checkBlock(pls, plasmaBlockMinedEvents, blockSubmitEvents, false, 0); err != nil { + if err := checkBlock(pls, plasmaBlockMinedEvents, blockSubmitEvents, false, 0, 3); err != nil { t.Fatal(err) } - // NRBEpoch#0.3 / PlasmaBlock#0.4 (2/2) + // NRE#0.3 / Block#0.4 (2/2) makeSampleTx(pls.rootchainManager) - if err := checkBlock(pls, plasmaBlockMinedEvents, blockSubmitEvents, false, 0); err != nil { + if err := checkBlock(pls, plasmaBlockMinedEvents, blockSubmitEvents, false, 0, 4); err != nil { t.Fatal(err) } - // ORBEpoch#0.4 / PlasmaBlock#0.5 (1/1): 4 ETH deposits, deposit 1 token from addr1 (Enter) - if err := checkBlock(pls, plasmaBlockMinedEvents, blockSubmitEvents, true, 0); err != nil { + // ORE#0.4 / Block#0.5 (1/1): 4 ETH deposits, deposit 1 token from addr1 (Enter) + if err := checkBlock(pls, plasmaBlockMinedEvents, blockSubmitEvents, true, 0, 5); err != nil { t.Fatal(err) } @@ -1094,40 +1095,46 @@ func TestScenario5(t *testing.T) { // withdraw 1 token from addr 1 startTokenWithdraw(t, pls.rootchainManager.rootchainContract, tokenInRootChain, tokenAddrInRootChain, key1, tokenAmount, big.NewInt(int64(pls.rootchainManager.state.costERO))) - // NRBEpoch#0.5 / PlasmaBlock#0.6 (1/2) + // NRE#0.5 / Block#0.6 (1/2) makeSampleTx(pls.rootchainManager) - if err := checkBlock(pls, plasmaBlockMinedEvents, blockSubmitEvents, false, 0); err != nil { + if err := checkBlock(pls, plasmaBlockMinedEvents, blockSubmitEvents, false, 0, 6); err != nil { t.Fatal(err) } - // NRBEpoch#0.5 / PlasmaBlock#0.7 (2/2) + // NRE#0.5 / Block#0.7 (2/2) makeSampleTx(pls.rootchainManager) - if err := checkBlock(pls, plasmaBlockMinedEvents, blockSubmitEvents, false, 0); err != nil { + if err := checkBlock(pls, plasmaBlockMinedEvents, blockSubmitEvents, false, 0, 7); err != nil { t.Fatal(err) } // make ERU startTokenWithdrawWithERU(t, pls.rootchainManager.rootchainContract, tokenInRootChain, tokenAddrInRootChain, key1, tokenAmount, big.NewInt(int64(pls.rootchainManager.state.costERO))) - // ORBEpoch#0.6 / PlasmaBlock#0.8 (1/1): 1 token withdrawal from addr1 (Exit) - if err := checkBlock(pls, plasmaBlockMinedEvents, blockSubmitEvents, true, 0); err != nil { + // ORE#0.6 / Block#0.8 (1/1): 1 token withdrawal from addr1 (Exit) + if err := checkBlock(pls, plasmaBlockMinedEvents, blockSubmitEvents, true, 0, 8); err != nil { t.Fatal(err) } // Prepare URB prepareToSubmitURB(t, pls.rootchainManager.rootchainContract, key1, big.NewInt(int64(pls.rootchainManager.state.costURBPrepare))) - // Fork: URBEpoch#1.5 / PlasmaBlock#1.6 (1/1) / parent: PlasmaBlock#0.6 - if err := checkBlock(pls, plasmaBlockMinedEvents, blockSubmitEvents, true, 1); err != nil { + fork0, _ := pls.rootchainManager.rootchainContract.Forks(baseCallOpt, big.NewInt(0)) + if fork0.ForkedBlock != 7 { + t.Fatalf("Expected chain is forked at block#7, but at block#%d", fork0.ForkedBlock) + } + + // Fork: URE#1.5 / Block#1.7 (1/1) / parent: Block#0.6 + if err := checkBlock(pls, plasmaBlockMinedEvents, blockSubmitEvents, true, 1, 7); err != nil { t.Fatal(err) } - // Rebased: ORBEpoch#1.6 / PlasmaBlock#1.7 (1/1): 1 ETH withdrawal (Exit) + // Rebased: ORE'#1.6 is empty / Reference Block#0.8 (only exit) // TODO (aiden): implement checkEpoch() to check empty epoch - // Rebased: NRBEpoch#1.7 / PlasmaBlock#1.8 (1/2) / rebased block of 0.7 - // check rebased txs - if err := checkBlock(pls, plasmaBlockMinedEvents, blockSubmitEvents, false, 1); err != nil { + // Rebased: NRE'#1.7 / Block#1.8 / Reference Block#0.7 + // NOTE: NRB#1.8 이 마이닝되지 않음. + // TODO: check rebased txs + if err := checkBlock(pls, plasmaBlockMinedEvents, blockSubmitEvents, false, 1, 8); err != nil { t.Fatal(err) } } @@ -1709,7 +1716,7 @@ func makeSampleTx(rcm *RootChainManager) error { return nil } -func checkBlock(pls *Plasma, pbMinedEvents *event.TypeMuxSubscription, pbSubmitedEvents chan *rootchain.RootChainBlockSubmitted, expectedIsRequest bool, expectedFork int64) error { +func checkBlock(pls *Plasma, pbMinedEvents *event.TypeMuxSubscription, pbSubmitedEvents chan *rootchain.RootChainBlockSubmitted, expectedIsRequest bool, expectedFork, expectedBlockNumber int64) error { outC := make(chan struct{}) errC := make(chan error) defer close(outC) @@ -1746,17 +1753,17 @@ func checkBlock(pls *Plasma, pbMinedEvents *event.TypeMuxSubscription, pbSubmite block := blockInfo.Block - log.Warn("Check PlasmaBlock Number", "localBlockNumber", pls.blockchain.CurrentBlock().NumberU64(), "minedBlockNumber", block.NumberU64(), "forkNumber", block.Difficulty().Uint64()) + log.Warn("Check Block Number", "expectedBlockNumber", expectedBlockNumber, "minedBlockNumber", block.NumberU64(), "forkNumber", block.Difficulty().Uint64()) // check block number. - if pls.blockchain.CurrentBlock().NumberU64() != block.NumberU64() { - errC <- errors.New(fmt.Sprintf("Expected block number: %d, actual block %d", block.NumberU64(), pls.blockchain.CurrentBlock().NumberU64())) + if expectedBlockNumber != block.Number().Int64() { + errC <- errors.New(fmt.Sprintf("Expected block number: %d, actual block %d", expectedBlockNumber, block.Number().Int64())) return } // check fork number if expectedFork != block.Difficulty().Int64() { - errC <- errors.New(fmt.Sprintf("PlasmaBlock Expected ForkNumber: %d, Actual ForkNumber %d", expectedFork, block.Difficulty().Int64())) + errC <- errors.New(fmt.Sprintf("Block Expected ForkNumber: %d, Actual ForkNumber %d", expectedFork, block.Difficulty().Int64())) return } @@ -1780,28 +1787,28 @@ func checkBlock(pls *Plasma, pbMinedEvents *event.TypeMuxSubscription, pbSubmite } if pb.IsRequest != block.IsRequest() { - errC <- errors.New(fmt.Sprintf("PlasmaBlock Expected isRequest: %t, Actual isRequest %t", pb.IsRequest, block.IsRequest())) + errC <- errors.New(fmt.Sprintf("Block Expected isRequest: %t, Actual isRequest %t", pb.IsRequest, block.IsRequest())) return } pbStateRoot := pb.StatesRoot[:] bStateRoot := block.Header().Root.Bytes() if bytes.Compare(pbStateRoot, bStateRoot) != 0 { - errC <- errors.New(fmt.Sprintf("PlasmaBlock Expected stateRoot: %s, Actual stateRoot: %s", pbStateRoot, bStateRoot)) + errC <- errors.New(fmt.Sprintf("Block Expected stateRoot: %s, Actual stateRoot: %s", pbStateRoot, bStateRoot)) return } pbTxRoot := pb.TransactionsRoot[:] bTxRoot := block.Header().TxHash.Bytes() if bytes.Compare(pbTxRoot, bTxRoot) != 0 { - errC <- errors.New(fmt.Sprintf("PlasmaBlock Expected txRoot: %s, Actual txRoot: %s", pbTxRoot, bTxRoot)) + errC <- errors.New(fmt.Sprintf("Block Expected txRoot: %s, Actual txRoot: %s", pbTxRoot, bTxRoot)) return } pbReceiptsRoot := pb.ReceiptsRoot[:] bReceiptsRoot := block.Header().ReceiptHash.Bytes() if bytes.Compare(pbReceiptsRoot, bReceiptsRoot) != 0 { - errC <- errors.New(fmt.Sprintf("PlasmaBlock Expected receiptsRoot: %s, Actual receiptsRoot: %s", pbReceiptsRoot, bReceiptsRoot)) + errC <- errors.New(fmt.Sprintf("Block Expected receiptsRoot: %s, Actual receiptsRoot: %s", pbReceiptsRoot, bReceiptsRoot)) return } log.Debug("Check block finished")