mirror of https://github.com/certusone/dc4bc.git
tendermint storage in tests (not working cause of gas)
This commit is contained in:
parent
f4d6c1e8a6
commit
f38d62d41a
|
@ -141,15 +141,22 @@ func RemoveContents(dir, mask string) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
var mnemonics = []string{
|
||||
"attack sister depth cook stick where decorate blush sting dry actual someone broccoli valid oak chronic view bubble mixture coil language obscure advice vague",
|
||||
"observe town orchard motion casino venue mule deny avoid resist arena original sniff kitten ice club october supply uncover tribe just volume mercy velvet",
|
||||
"exhibit shallow endless hole position weapon gallery subway train tail fire feed planet ship picture decide snap picnic merge citizen have cruel celery iron",
|
||||
"where join over avocado song kick jelly sentence step plate combine awkward increase tomato purity friend distance magic inmate spoon soft student clerk kitchen",
|
||||
}
|
||||
|
||||
func TestFullFlow(t *testing.T) {
|
||||
_ = RemoveContents("/tmp", "dc4bc_*")
|
||||
defer func() { _ = RemoveContents("/tmp", "dc4bc_*") }()
|
||||
|
||||
var numNodes = 4
|
||||
var threshold = 2
|
||||
var storagePath = "/tmp/dc4bc_storage"
|
||||
//var storagePath = "/tmp/dc4bc_storage"
|
||||
var nodes = make([]*node, numNodes)
|
||||
startingPort := 8080
|
||||
startingPort := 8085
|
||||
for nodeID := 0; nodeID < numNodes; nodeID++ {
|
||||
var ctx = context.Background()
|
||||
var userName = fmt.Sprintf("node_%d", nodeID)
|
||||
|
@ -158,7 +165,7 @@ func TestFullFlow(t *testing.T) {
|
|||
t.Fatalf("node %d failed to init state: %v\n", nodeID, err)
|
||||
}
|
||||
|
||||
stg, err := storage.NewFileStorage(storagePath)
|
||||
stg, err := storage.NewTendermintStorage("http://0.0.0.0:1317", fmt.Sprintf("user%d", nodeID), "bulletin", "test_topic9", "12345678", mnemonics[nodeID])
|
||||
if err != nil {
|
||||
t.Fatalf("node %d failed to init storage: %v\n", nodeID, err)
|
||||
}
|
||||
|
@ -250,7 +257,7 @@ func TestFullFlow(t *testing.T) {
|
|||
t.Fatalf("failed to send HTTP request to start DKG: %v\n", err)
|
||||
}
|
||||
|
||||
time.Sleep(10 * time.Second)
|
||||
time.Sleep(300 * time.Second)
|
||||
log.Println("Propose message to sign")
|
||||
|
||||
dkgRoundID := md5.Sum(messageDataBz)
|
||||
|
|
2
go.mod
2
go.mod
|
@ -27,4 +27,4 @@ require (
|
|||
lukechampine.com/frand v1.3.0
|
||||
)
|
||||
|
||||
replace github.com/ethereum/go-ethereum => github.com/ethereum/go-ethereum v1.9.22
|
||||
replace github.com/ethereum/go-ethereum => github.com/ethereum/go-ethereum v1.9.22
|
|
@ -167,6 +167,7 @@ func (ts *TendermintStorage) signTx(tx types.StdTx) (*types.StdTx, error) {
|
|||
txBuilder := auth.NewTxBuilder(auth.DefaultTxEncoder(app.MakeCodec()), account.GetAccountNumber(),
|
||||
account.GetSequence(), tx.GetGas(), 0, false, ts.chainID, tx.GetMemo(),
|
||||
tx.Fee.Amount, tx.Fee.GasPrices()).WithKeybase(ts.keybase)
|
||||
tx.Fee.Gas = tx.GetGas() * 2
|
||||
signedTx, err := txBuilder.SignStdTx(ts.name, ts.password, tx, false)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to sign tx: %w", err)
|
||||
|
@ -174,6 +175,11 @@ func (ts *TendermintStorage) signTx(tx types.StdTx) (*types.StdTx, error) {
|
|||
return &signedTx, nil
|
||||
}
|
||||
|
||||
type broadcastTxResponse struct {
|
||||
Code int `json:"code"`
|
||||
RawLog string `json:"raw_log"`
|
||||
}
|
||||
|
||||
func (ts *TendermintStorage) broadcastTx(tx types.StdTx) error {
|
||||
var req authRest.BroadcastReq
|
||||
req.Tx = tx
|
||||
|
@ -183,10 +189,17 @@ func (ts *TendermintStorage) broadcastTx(tx types.StdTx) error {
|
|||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if _, err = rawPostRequest(fmt.Sprintf("%s/txs", ts.nodeEndpoint),
|
||||
"application/json", data); err != nil {
|
||||
resp, err := rawPostRequest(fmt.Sprintf("%s/txs", ts.nodeEndpoint), "application/json", data)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
var txResp broadcastTxResponse
|
||||
if err = json.Unmarshal(resp, &txResp); err != nil {
|
||||
return fmt.Errorf("failed to unmarshal response: %w", err)
|
||||
}
|
||||
if txResp.Code != 0 {
|
||||
return fmt.Errorf("failed to execute tx: %s", txResp.RawLog)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
|
@ -228,7 +241,7 @@ func (ts *TendermintStorage) GetMessages(offset uint64) ([]Message, error) {
|
|||
if err = json.Unmarshal(respBody, &errorResp); err != nil {
|
||||
return nil, fmt.Errorf("failed to unmarshal response: %w", err)
|
||||
}
|
||||
return nil, fmt.Errorf("%w", err)
|
||||
return nil, fmt.Errorf("failed to get messages: %s", errorResp.Error)
|
||||
}
|
||||
|
||||
if err = json.Unmarshal(respBody, &messagesResponse); err != nil {
|
||||
|
@ -245,7 +258,7 @@ func (ts *TendermintStorage) GetMessages(offset uint64) ([]Message, error) {
|
|||
ID: message.ID,
|
||||
DkgRoundID: message.DKGRoundID,
|
||||
Offset: parsedOffset,
|
||||
Event: message.Topic,
|
||||
Event: message.Event,
|
||||
Data: message.Data,
|
||||
Signature: message.Signature,
|
||||
SenderAddr: message.Sender,
|
||||
|
|
|
@ -15,7 +15,7 @@ const (
|
|||
)
|
||||
|
||||
func TestNewTendermintStorage(t *testing.T) {
|
||||
N := 10
|
||||
N := 100
|
||||
offset := 4
|
||||
|
||||
ts, err := NewTendermintStorage(TestEndpoint, TestUserName, TestChainID, TestTopic, TestPassword, TestMnemonic)
|
||||
|
|
Loading…
Reference in New Issue