-
Notifications
You must be signed in to change notification settings - Fork 51
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2651 from 0chain/add/conductor-tests-for-blobber-…
…and-validator Add/conductor tests for blobber and validator
- Loading branch information
Showing
43 changed files
with
1,419 additions
and
212 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
//go:build !integration_tests | ||
// +build !integration_tests | ||
|
||
package chain | ||
|
||
import ( | ||
"context" | ||
|
||
"0chain.net/chaincore/block" | ||
) | ||
|
||
func (c *Chain) postFinalize(ctx context.Context, fb *block.Block) error { | ||
return nil | ||
} |
70 changes: 70 additions & 0 deletions
70
code/go/0chain.net/chaincore/chain/post_finalize_integration_tests.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
//go:build integration_tests | ||
// +build integration_tests | ||
|
||
package chain | ||
|
||
import ( | ||
"context" | ||
|
||
"0chain.net/chaincore/block" | ||
"0chain.net/chaincore/transaction" | ||
crpc "0chain.net/conductor/conductrpc" | ||
"github.com/0chain/common/core/logging" | ||
"go.uber.org/zap" | ||
) | ||
|
||
type TxnHandler func(txn *transaction.Transaction, client *crpc.Entity) error | ||
|
||
var txnHandlers = map[string] TxnHandler{ | ||
"generate_challenge": func(txn *transaction.Transaction, client *crpc.Entity) error{ | ||
client.ChallengeGenerated(client.State().GenerateChallenge.BlobberID) | ||
return nil | ||
}, | ||
"challenge_response": func(txn *transaction.Transaction, client *crpc.Entity) error{ | ||
switch txn.TransactionOutput { | ||
case "challenge passed by blobber": | ||
status := 0 | ||
if txn.Status == 1 { | ||
status = 1 | ||
} | ||
client.SendChallengeStatus(map[string]interface{}{ | ||
"blobber_id": txn.ClientID, | ||
"status": status, | ||
}) | ||
case "Challenge Failed by Blobber": | ||
client.SendChallengeStatus(map[string]interface{}{ | ||
"error": txn.TransactionData, | ||
"status": 0, | ||
"response": txn.TransactionOutput, | ||
"blobber_id": txn.ClientID, | ||
}) | ||
} | ||
return nil | ||
}, | ||
} | ||
|
||
func (c *Chain) postFinalize(ctx context.Context, fb *block.Block) error { | ||
client := crpc.Client() | ||
for _, txn := range fb.Txns { | ||
handler, ok := txnHandlers[txn.FunctionName] | ||
if !ok { | ||
continue | ||
} | ||
logging.Logger.Info("post_finalize processing txn", | ||
zap.Any("function_name", txn.FunctionName), | ||
zap.Any("hash", txn.Hash), | ||
zap.Any("output", txn.TransactionOutput), | ||
) | ||
err := handler(txn, client) | ||
if err != nil { | ||
logging.Logger.Error("post_finalize txn error", | ||
zap.Int64("round", fb.Round), | ||
zap.String("hash", fb.Hash), | ||
zap.Any("txn", txn), | ||
zap.Error(err), | ||
) | ||
} | ||
} | ||
|
||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.