sharding/contracts: hash digest instead of byte array

Former-commit-id: e6d1149f737e0c21b8ef45712c30265ee699ec96 [formerly 72863268f45b7ca71d9990422cc3bd5b0a75b24d]
Former-commit-id: 9059a3971e64abda1939a5aaa6fee8b2e8e7e605
This commit is contained in:
Terence Tsao 2018-05-25 10:20:51 -07:00
parent fd2124d6c0
commit bac0c74b6b

View File

@ -73,8 +73,7 @@ func (s *smcTestHelper) fastForward(p int) {
} }
} }
// registerNotaries is a helper function register notaries in batch, // registerNotaries is a helper function register notaries in batch.
// it also verifies notary registration is successful.
func (s *smcTestHelper) registerNotaries(deposit *big.Int, params ...int) error { func (s *smcTestHelper) registerNotaries(deposit *big.Int, params ...int) error {
for i := params[0]; i < params[1]; i++ { for i := params[0]; i < params[1]; i++ {
s.testAccounts[i].txOpts.Value = deposit s.testAccounts[i].txOpts.Value = deposit
@ -111,8 +110,7 @@ func (s *smcTestHelper) registerNotaries(deposit *big.Int, params ...int) error
return nil return nil
} }
// deregisterNotaries is a helper function that deregister notaries in batch, // deregisterNotaries is a helper function that deregister notaries in batch.
// it also verifies notary deregistration is successful.
func (s *smcTestHelper) deregisterNotaries(params ...int) error { func (s *smcTestHelper) deregisterNotaries(params ...int) error {
for i := params[0]; i < params[1]; i++ { for i := params[0]; i < params[1]; i++ {
s.testAccounts[i].txOpts.Value = big.NewInt(0) s.testAccounts[i].txOpts.Value = big.NewInt(0)
@ -147,8 +145,7 @@ func (s *smcTestHelper) deregisterNotaries(params ...int) error {
return nil return nil
} }
// addHeader is a helper function to add header to smc, // addHeader is a helper function to add header to smc.
// it also verifies header is correctly added to the SMC.
func (s *smcTestHelper) addHeader(a *testAccount, shard *big.Int, period *big.Int, chunkRoot uint8) error { func (s *smcTestHelper) addHeader(a *testAccount, shard *big.Int, period *big.Int, chunkRoot uint8) error {
_, err := s.smc.AddHeader(a.txOpts, shard, period, [32]byte{chunkRoot}) _, err := s.smc.AddHeader(a.txOpts, shard, period, [32]byte{chunkRoot})
if err != nil { if err != nil {
@ -186,8 +183,7 @@ func (s *smcTestHelper) addHeader(a *testAccount, shard *big.Int, period *big.In
return nil return nil
} }
// submitVote is a helper function for notary to submit vote on a given header, // submitVote is a helper function for notary to submit vote on a given header.
// it also verifies vote is properly submitted and casted.
func (s *smcTestHelper) submitVote(a *testAccount, shard *big.Int, period *big.Int, index *big.Int, chunkRoot uint8) error { func (s *smcTestHelper) submitVote(a *testAccount, shard *big.Int, period *big.Int, index *big.Int, chunkRoot uint8) error {
_, err := s.smc.SubmitVote(a.txOpts, shard, period, index, [32]byte{chunkRoot}) _, err := s.smc.SubmitVote(a.txOpts, shard, period, index, [32]byte{chunkRoot})
if err != nil { if err != nil {
@ -214,7 +210,7 @@ func (s *smcTestHelper) submitVote(a *testAccount, shard *big.Int, period *big.I
return fmt.Errorf("incorrect notary address in submitVote log. Want: %v Got: %v", s.testAccounts[0].addr, a.addr) return fmt.Errorf("incorrect notary address in submitVote log. Want: %v Got: %v", s.testAccounts[0].addr, a.addr)
} }
if log.Event.ChunkRoot != [32]byte{chunkRoot} { if log.Event.ChunkRoot != [32]byte{chunkRoot} {
return fmt.Errorf("chunk root missmatch in submitVote log. Want: %v Got: %v", [32]byte{chunkRoot}, log.Event.ChunkRoot) return fmt.Errorf("chunk root missmatch in submitVote log. Want: %v Got: %v", common.BytesToHash([]byte{chunkRoot}), common.BytesToHash(log.Event.ChunkRoot[:]))
} }
return nil return nil
} }