-
Notifications
You must be signed in to change notification settings - Fork 45
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: add options for rpc retry/timeout and tx nonce * test: batch upload * fix: nonce
- Loading branch information
1 parent
e96480e
commit 369dfb5
Showing
9 changed files
with
180 additions
and
21 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
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
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
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,30 @@ | ||
import os | ||
|
||
from test_framework.test_framework import TestFramework | ||
from config.node_config import GENESIS_PRIV_KEY | ||
from utility.run_go_test import run_go_test | ||
|
||
class BatchUploadTest(TestFramework): | ||
def setup_params(self): | ||
self.num_blockchain_nodes = 1 | ||
self.num_nodes = 1 | ||
|
||
def run_test(self): | ||
ports = ",".join([x.rpc_url.split(":")[-1] for x in self.nodes]) | ||
self.setup_indexer(self.nodes[0].rpc_url, self.nodes[0].rpc_url, ports) | ||
test_args = [ | ||
"go", | ||
"run", | ||
os.path.join(os.path.dirname(__file__), "go_tests", "batch_upload_test", "main.go"), | ||
# arguments passed to go | ||
GENESIS_PRIV_KEY, | ||
self.contract.address(), | ||
self.blockchain_nodes[0].rpc_url, | ||
",".join([x.rpc_url for x in self.nodes]), | ||
self.indexer_rpc_url | ||
] | ||
run_go_test(self.root_dir, test_args) | ||
|
||
|
||
if __name__ == "__main__": | ||
BatchUploadTest().main() |
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,78 @@ | ||
package main | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"os" | ||
"strings" | ||
"time" | ||
|
||
"github.com/0glabs/0g-storage-client/common" | ||
"github.com/0glabs/0g-storage-client/common/blockchain" | ||
"github.com/0glabs/0g-storage-client/common/util" | ||
"github.com/0glabs/0g-storage-client/contract" | ||
"github.com/0glabs/0g-storage-client/core" | ||
"github.com/0glabs/0g-storage-client/indexer" | ||
"github.com/0glabs/0g-storage-client/transfer" | ||
eth_common "github.com/ethereum/go-ethereum/common" | ||
"github.com/pkg/errors" | ||
"github.com/sirupsen/logrus" | ||
) | ||
|
||
func runTest() error { | ||
ctx := context.Background() | ||
// load args | ||
args := os.Args[1:] | ||
key := args[0] | ||
contractAddr := eth_common.HexToAddress(args[1]) | ||
chainUrl := args[2] | ||
zgsNodeUrls := strings.Split(args[3], ",") | ||
indexerUrl := args[4] | ||
|
||
w3client := blockchain.MustNewWeb3(chainUrl, key) | ||
defer w3client.Close() | ||
flow, err := contract.NewFlowContract(contractAddr, w3client) | ||
if err != nil { | ||
return fmt.Errorf("failed to create flow contract") | ||
} | ||
// batch upload | ||
datas := make([]core.IterableData, 10) | ||
opts := make([]transfer.UploadOption, 10) | ||
for i := 0; i < 10; i += 1 { | ||
datas[i], err = core.NewDataInMemory([]byte(fmt.Sprintf("indexer_test_data_%v", i))) | ||
if err != nil { | ||
return errors.WithMessage(err, "failed to initialize data") | ||
} | ||
opts[i] = transfer.UploadOption{ | ||
FinalityRequired: true, | ||
} | ||
} | ||
indexerClient, err := indexer.NewClient(indexerUrl, indexer.IndexerClientOption{LogOption: common.LogOption{Logger: logrus.StandardLogger()}}) | ||
if err != nil { | ||
return errors.WithMessage(err, "failed to initialize indexer client") | ||
} | ||
_, roots, err := indexerClient.BatchUpload(ctx, flow, datas, true, opts) | ||
if err != nil { | ||
return errors.WithMessage(err, "failed to upload file") | ||
} | ||
// check file location | ||
for _, root := range roots { | ||
locations, err := indexerClient.GetFileLocations(ctx, root.Hex()) | ||
if err != nil { | ||
return errors.WithMessage(err, "failed to get file locations") | ||
} | ||
if len(locations) != 1 { | ||
return fmt.Errorf("unexpected file location length: %v", len(locations)) | ||
} | ||
if locations[0].URL != zgsNodeUrls[0] { | ||
return fmt.Errorf("unexpected file location: %v", locations[0].URL) | ||
} | ||
} | ||
return nil | ||
} | ||
|
||
func main() { | ||
if err := util.WaitUntil(runTest, time.Minute*3); err != nil { | ||
logrus.WithError(err).Fatalf("batch upload test failed") | ||
} | ||
} |
Oops, something went wrong.