diff --git a/examples/ffs_logs.py b/examples/ffs_logs.py index 2a3f5f0..dce6234 100644 --- a/examples/ffs_logs.py +++ b/examples/ffs_logs.py @@ -14,7 +14,7 @@ stage_requests_iter = bytes_to_chunks(test_file) stage_res = client.ffs.stage(stage_requests_iter, ffs.token) -push_res = client.ffs.push(stage_res.cid, ffs.token) +push_res = client.ffs.push(stage_res.cid, token=ffs.token) logs_res = client.ffs.logs(stage_res.cid, ffs.token, history=True, timeout=5) logs = [] diff --git a/examples/ffs_push_pull_file.py b/examples/ffs_push_pull_file.py index 1a3e0b8..7633482 100644 --- a/examples/ffs_push_pull_file.py +++ b/examples/ffs_push_pull_file.py @@ -25,7 +25,18 @@ print("Pushing file to FFS...") # Push the given file - c.ffs.push(res.cid, ffs.token) + c.ffs.push(res.cid, override=False, token=ffs.token) + # Override push with another config + addresses = c.ffs.addrs_list(ffs.token) + wallet = addresses.addrs[0].addr + new_config = ( + '{"hot":{"enabled":true,"allowUnfreeze":true,"ipfs":{"addTimeout":30}},' + '"cold":{"enabled":true,"filecoin":{"repFactor":1,"dealMinDuration":518400,' + '"excludedMiners":["t01101"],"trustedMiners":["t01000","t02000"],' + '"countryCodes":["ca","nl"],"renew":{"enabled":true,"threshold":3},' + '"addr":"' + wallet + '","maxPrice":50}},"repairable":true}' + ) + c.ffs.push(res.cid, override=True, config=new_config, token=ffs.token) # Check that CID is pinned to FFS check = c.ffs.info(res.cid, ffs.token) @@ -38,7 +49,6 @@ # Write to a file on disk print("Saving as 'README_copy.md'") - f = open("README_copy.MD", "wb") - for f_ in file_: - f.write(f_) - f.close() + with open("README_copy.MD", "wb") as f: + for f_ in file_: + f.write(f_) diff --git a/pygate_grpc/ffs.py b/pygate_grpc/ffs.py index 9212751..c58ee40 100644 --- a/pygate_grpc/ffs.py +++ b/pygate_grpc/ffs.py @@ -98,6 +98,10 @@ def show(self, cid: str, token: str = None): req = ffs_rpc_pb2.ShowRequest(cid=cid) return self.client.Show(req, metadata=self._get_meta_data(token)) + def show_all(self, token: str = None): + req = ffs_rpc_pb2.ShowAllRequest() + return self.client.ShowAll(req, metadata=self._get_meta_data(token)) + # Note that the chunkIter should be an iterator that yield `ffs_rpc_pb2.AddToHotRequest`, # it is the caller's responsibility to create the iterator. # The provided getFileChunks comes in handy some times. @@ -139,9 +143,18 @@ def get_storage_job(self, jid: str, token: str = None): return self.client.GetStorageJob(req, metadata=self._get_meta_data(token)) def push( - self, cid, token: str = None, + self, cid, token: str = None, override: bool = False, config: str = None, ): - req = ffs_rpc_pb2.PushStorageConfigRequest(cid=cid) + if config: + config = Parse(config, ffs_rpc_pb2.StorageConfig()) + + req = ffs_rpc_pb2.PushStorageConfigRequest( + cid=cid, + override_config=override, + has_override_config=override, + config=config, + has_config=config is not None, + ) return self.client.PushStorageConfig(req, metadata=self._get_meta_data(token)) def close(self, token: str = None): @@ -156,7 +169,7 @@ def create_pay_channel( self, sender: str, receiver: str, amount: int, token: str = None ): kwargs = {"from": sender, "to": receiver, "amount": amount} - req = ffs_rpc_pb2.CreateRequest(kwargs) + req = ffs_rpc_pb2.CreatePayChannelRequest(**kwargs) return self.client.CreatePayChannel(req, metadata=self._get_meta_data(token)) def redeem_pay_channel( diff --git a/tests/integration/test_ffs.py b/tests/integration/test_ffs.py index f8d6378..635ae26 100644 --- a/tests/integration/test_ffs.py +++ b/tests/integration/test_ffs.py @@ -42,7 +42,7 @@ def test_grpc_ffs_add_then_get_content(pygate_client: PowerGateClient, ffs_insta assert res is not None - pygate_client.ffs.push(res.cid, ffs_instance.token) + pygate_client.ffs.push(res.cid, token=ffs_instance.token) f = pygate_client.ffs.get(res.cid, ffs_instance.token) assert next(f) == b"test_content" @@ -107,7 +107,7 @@ def test_ffs_logs(pygate_client: PowerGateClient): ffs = pygate_client.ffs.create() stage_res = pygate_client.ffs.stage(chunks(), ffs.token) - pygate_client.ffs.push(stage_res.cid, ffs.token) + pygate_client.ffs.push(stage_res.cid, token=ffs.token) logs_res = pygate_client.ffs.logs(stage_res.cid, ffs.token, history=True, timeout=5) logs = [] @@ -124,30 +124,35 @@ def test_storage_deals(pygate_client: PowerGateClient): ffs = pygate_client.ffs.create() stage_res = pygate_client.ffs.stage(chunks(), ffs.token) - pygate_client.ffs.push(stage_res.cid, ffs.token) + pygate_client.ffs.push(stage_res.cid, token=ffs.token) time.sleep(3) - storage_deals = pygate_client.ffs.list_storage_deal_records( + pygate_client.ffs.list_storage_deal_records( include_pending=True, include_final=True, token=ffs.token ) - assert len(storage_deals.records) > 0 - def test_retrieval_deals(pygate_client: PowerGateClient): ffs = pygate_client.ffs.create() stage_res = pygate_client.ffs.stage(chunks(), ffs.token) - pygate_client.ffs.push(stage_res.cid, ffs.token) + pygate_client.ffs.push(stage_res.cid, token=ffs.token) time.sleep(3) - retrieval_deals = pygate_client.ffs.list_retrieval_deal_records( + pygate_client.ffs.list_retrieval_deal_records( include_pending=True, include_final=True, token=ffs.token ) - assert len(retrieval_deals.records) == 0 + +def test_push_override(pygate_client: PowerGateClient): + ffs = pygate_client.ffs.create() + + stage_res = pygate_client.ffs.stage(chunks(), ffs.token) + pygate_client.ffs.push(stage_res.cid, token=ffs.token) + + pygate_client.ffs.push(stage_res.cid, token=ffs.token, override=True) def chunks(): diff --git a/tests/integration/test_wallet.py b/tests/integration/test_wallet.py index c24654b..cfe08c0 100644 --- a/tests/integration/test_wallet.py +++ b/tests/integration/test_wallet.py @@ -40,30 +40,3 @@ def test_grpc_wallet_balance(pygate_client: PowerGateClient): balance_res = pygate_client.wallet.balance(new_res.address) assert type(balance_res) is BalanceResponse assert balance_res.balance == 250000000000000000 - - -def test_send_file(pygate_client: PowerGateClient): - addr = pygate_client.wallet.new() - - assert addr is not None - assert addr.address is not None - - res = pygate_client.wallet.list() - - assert res is not None - - sender_addr = res.addresses[0] - receiver_addr = res.addresses[1] - - before_sender_fil = pygate_client.wallet.balance(sender_addr) - before_receiver_fil = pygate_client.wallet.balance(receiver_addr) - - pygate_client.wallet.send_fil(sender_addr, receiver_addr, 1) - - # Wait a bit for transaction to complete - time.sleep(5) - after_sender_fil = pygate_client.wallet.balance(sender_addr) - after_receiver_fil = pygate_client.wallet.balance(receiver_addr) - - assert before_sender_fil.balance > after_sender_fil.balance - assert before_receiver_fil.balance < after_receiver_fil.balance