Skip to content

Commit

Permalink
feat(act): corrct history address
Browse files Browse the repository at this point in the history
  • Loading branch information
Ferenc Sárai committed Jul 31, 2024
1 parent 7e8123a commit eb9b62e
Showing 1 changed file with 48 additions and 23 deletions.
71 changes: 48 additions & 23 deletions pkg/check/act/act.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,26 +69,21 @@ func (c *Check) Run(ctx context.Context, cluster orchestration.Cluster, opts int
fullNodes := cluster.FullNodeNames()
lightNodes := cluster.LightNodeNames()

//sortedNodes := cluster.NodeNames()
//upNodeName := sortedNodes[0]
upNodeName := lightNodes[0]
upClient := clients[upNodeName]
addr, _ := upClient.Addresses(ctx)
publisher, _ := swarm.ParseHexAddress(addr.PublicKey)

//nodeName1 := sortedNodes[1]
nodeName1 := fullNodes[0]
client1 := clients[nodeName1]
addr1, _ := client1.Addresses(ctx)
pubk1, _ := swarm.ParseHexAddress(addr1.PublicKey)

//nodeName2 := sortedNodes[2]
nodeName2 := fullNodes[1]
client2 := clients[nodeName2]
addr2, _ := client2.Addresses(ctx)
pubk2, _ := swarm.ParseHexAddress(addr2.PublicKey)

//odeName3 := sortedNodes[3]
nodeName3 := fullNodes[2]
client3 := clients[nodeName3]
addr3, _ := client3.Addresses(ctx)
Expand All @@ -107,58 +102,70 @@ func (c *Check) Run(ctx context.Context, cluster orchestration.Cluster, opts int
}

// upload act file
// ----------------------------------------------
// Given batch is used for the upload
// When the file is uploaded to the node
// Then the file is uploaded successfully
uErr := upClient.UploadActFile(ctx, &file, api.UploadOptions{BatchID: batchID})
if uErr != nil {
return fmt.Errorf("node %s: %w", upNodeName, uErr)
}
c.logger.Info("ACT file uploaded")
time.Sleep(1 * time.Second)

time.Sleep(5 * time.Second)

// download act file
// ----------------------------------------------
// Given the file is uploaded to the node
// When the file is downloaded from the node
// Then the file is downloaded successfully
act := true
fileAddress := file.Address()
history := file.HistroryAddress()
// download act file
size, hash, err := upClient.DownloadActFile(ctx, fileAddress, &api.DownloadOptions{Act: &act, ActPublicKey: &publisher, ActHistoryAddress: &history})
if err != nil {
return fmt.Errorf("node %s: %w", upNodeName, err)
}

if !bytes.Equal(file.Hash(), hash) {
c.logger.Infof("Node %s. ACT file hash not equal. Uploaded size: %d Downloaded size: %d File: %s", upNodeName, file.Size(), size, fileAddress.String())
return errors.New("ACT file retrieval - hash error")
}

c.logger.Info("ACT file downloaded")
time.Sleep(1 * time.Second)

// download act file with wrong public key
// ----------------------------------------------
// Given the file is uploaded to the node
// When the file is downloaded from the node with wrong public key
// Then the file download is denied
notPublisher := pubk1
_, _, notPErr := upClient.DownloadActFile(ctx, file.Address(), &api.DownloadOptions{Act: &act, ActPublicKey: &notPublisher, ActHistoryAddress: &history})
if notPErr == nil {
return fmt.Errorf("node %s: File downloaded with wrong public key successfully - this is an error", upNodeName)
}

c.logger.Info("ACT Access denied with incorrect public key")
time.Sleep(5 * time.Second)

// add grantees list
// ----------------------------------------------
// Given the file is uploaded to the node (fileHis)
// When the grantees are added to the file
// Then the grantees are added successfully
gFile := bee.NewBufferFile("grantees.json", bytes.NewBuffer([]byte(`{ "grantees": [
"`+pubk2.String()+`",
"`+pubk3.String()+`"
]
}`)))

fileHis := file.HistroryAddress()
err = upClient.AddActGrantees(ctx, &gFile, api.UploadOptions{BatchID: batchID, ActHistoryAddress: fileHis})
if err != nil {
return fmt.Errorf("node %s: add grantees error: %w", upNodeName, err)
}

c.logger.Info("ACT grantees added")
time.Sleep(1 * time.Second)

// list grantees
// ----------------------------------------------
// Given the file is uploaded to the node (gFile)
// When the grantees are listed
// Then the grantees are listed successfully
addresses, gErr := upClient.GetActGrantees(ctx, gFile.Address())
if gErr != nil {
return fmt.Errorf("node %s: GetActGrantees: %w", upNodeName, gErr)
Expand All @@ -169,11 +176,13 @@ func (c *Check) Run(ctx context.Context, cluster orchestration.Cluster, opts int
if len(addresses) != 2 {
return fmt.Errorf("node %s: GetActGrantees: addresses length is not 2", upNodeName)
}

c.logger.Info("ACT grantees listed")
time.Sleep(1 * time.Second)

// download act file with teh publisher
// download act file with the publisher after create grantees
// ----------------------------------------------
// Given the grantee is added to the file
// When the file is downloaded from the node with the publisher
// Then the file is downloaded successfully
h := gFile.HistroryAddress()
size0, hash0, err0 := upClient.DownloadActFile(ctx, fileAddress, &api.DownloadOptions{Act: &act, ActPublicKey: &publisher, ActHistoryAddress: &h})
if err0 != nil {
Expand All @@ -184,7 +193,12 @@ func (c *Check) Run(ctx context.Context, cluster orchestration.Cluster, opts int
return errors.New("ACT file retrieval - hash error")
}
c.logger.Info("ACT file downloaded with the publisher")

// download act file with the grantee
// ----------------------------------------------
// Given the grantee is added to the file
// When the file is downloaded from the node with the grantee
// Then the file is downloaded successfully
his := gFile.HistroryAddress()
size1, hash1, err1 := client2.DownloadActFile(ctx, fileAddress, &api.DownloadOptions{Act: &act, ActPublicKey: &publisher, ActHistoryAddress: &his})
if err1 != nil {
Expand All @@ -197,6 +211,10 @@ func (c *Check) Run(ctx context.Context, cluster orchestration.Cluster, opts int
c.logger.Info("ACT file downloaded with the grantee")

// patch grantees
// ----------------------------------------------
// Given the grantee is added to the file (gFile)
// When the grantees are patched
// Then the grantees are patched successfully
pFile := bee.NewBufferFile("grantees-patch.json", bytes.NewBuffer([]byte(`{
"add": [
"`+pubk1.String()+`"
Expand All @@ -211,10 +229,14 @@ func (c *Check) Run(ctx context.Context, cluster orchestration.Cluster, opts int
if pErr != nil {
return fmt.Errorf("node %s: PatchActGrantees: %w", upNodeName, pErr)
}

c.logger.Info("ACT grantees patched")
time.Sleep(5 * time.Second)

// list grantees after patch
// ----------------------------------------------
// Given the grantee is patched
// When the grantees are listed after patch
// Then the grantees are listed successfully
patchAddresses, patchErr := upClient.GetActGrantees(ctx, pFile.Address())
if patchErr != nil {
return fmt.Errorf("node %s: GetActGrantees after patch: %w", upNodeName, patchErr)
Expand All @@ -227,8 +249,12 @@ func (c *Check) Run(ctx context.Context, cluster orchestration.Cluster, opts int
}
c.logger.Info("ACT grantees listed after patch")

// download act file with the grantee after patch
his2 := gFile.HistroryAddress()
// download act file with the new grantee after patch
// ----------------------------------------------
// Given the grantee is patched
// When the file is downloaded from the node with the new grantee
// Then the file is downloaded successfully
his2 := pFile.HistroryAddress()
size2, hash2, err2 := client1.DownloadActFile(ctx, fileAddress, &api.DownloadOptions{Act: &act, ActPublicKey: &publisher, ActHistoryAddress: &his2})
if err2 != nil {
return fmt.Errorf("node %s: %w", nodeName1, err2)
Expand All @@ -237,9 +263,8 @@ func (c *Check) Run(ctx context.Context, cluster orchestration.Cluster, opts int
c.logger.Infof("Node %s. ACT file hash not equal. Uploaded size: %d Downloaded size: %d File: %s", nodeName1, file.Size(), size2, fileAddress.String())
return errors.New("ACT file retrieval - hash error")
}
c.logger.Info("ACT file downloaded with the grantee after patch")
c.logger.Info("ACT file downloaded with the new grantee after patch")

c.logger.Info("ACT test completed")
return

}

0 comments on commit eb9b62e

Please sign in to comment.