Skip to content
This repository has been archived by the owner on Aug 23, 2020. It is now read-only.

Add spent addresses export test #1561

Open
wants to merge 25 commits into
base: dev
Choose a base branch
from

Conversation

DyrellC
Copy link
Contributor

@DyrellC DyrellC commented Aug 4, 2019

Description

Adds a regression test for exporting and importing spentAddresses.txt files using the export-spent and merge-spent iri-extension tools. The tests export the spent addresses of one node into a file and checks to ensure that they have been exported correctly. It then imports the same addresses into an empty node and checks that the addresses were added as spent addresses.

**Note: This test currently only tests with one spent address db to test and is an incomplete PR until further notice. It should not be merged until the additional test has been added, but needs to be tested in the build pipeline to ensure it is working correctly.

Fixes #1468

Type of change

  • Enhancement (a non-breaking change which adds functionality)

How Has This Been Tested?

  • Locally tested prior to change in file location
  • Testing on buildkite pipeline to ensure pod file locations are correct **

Checklist:

  • My code follows the style guidelines for this project
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas

@iotaledger iotaledger deleted a comment Aug 4, 2019
@iotaledger iotaledger deleted a comment Aug 4, 2019
@iotaledger iotaledger deleted a comment Aug 4, 2019
@iotaledger iotaledger deleted a comment Aug 4, 2019
@iotaledger iotaledger deleted a comment Aug 4, 2019
@iotaledger iotaledger deleted a comment Aug 4, 2019
@iotaledger iotaledger deleted a comment Aug 4, 2019
@iotaledger iotaledger deleted a comment Aug 4, 2019
@iotaledger iotaledger deleted a comment Aug 4, 2019
@iotaledger iotaledger deleted a comment Aug 4, 2019
@iotaledger iotaledger deleted a comment Aug 4, 2019
@iotaledger iotaledger deleted a comment Aug 4, 2019
@iotaledger iotaledger deleted a comment Aug 4, 2019
@iotaledger iotaledger deleted a comment Aug 4, 2019
@iotaledger iotaledger deleted a comment Aug 4, 2019
@iotaledger iotaledger deleted a comment Aug 4, 2019
@iotaledger iotaledger deleted a comment Aug 4, 2019
return Response.create({
amount: hashes.length,
fileName: fileName,
sizeInMb: new java.lang.Integer(file.length() / (1024 * 1024)),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

}

return {
amount: amount
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:param node: The node that the spent addresses will be merged into
"""
args = step.hashes
for x in range(len(args)):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

writer.write(hashes.length.toString() + separator);

// Write spent addresses
for (var i=0; i<hashes.length; i++){
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

var digest = java.security.MessageDigest.getInstance("SHA-256");
for (var i=0; i<hashes.length; i++){
// Update with hash bytes
digest.update(hashes[i].bytes());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.


var spentAddressProvider = IOTA.spentAddressesProvider

var iri = com.iota.iri;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

});
}

API.put("generateSpentAddressesFile", new Callable({ call: generate }))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.


// Write spent addresses
for (var i=0; i<hashes.length; i++){
var hash = hashes[i].toString();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@@ -0,0 +1,147 @@
var System = java.lang.System;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

}
} else if (line.length() !== 64) {
// This must be the amount
amount = Number(line);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

}
}
} else {
log.error("File {} did not exist on disk.. ignoring!", fileName)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

});
}

API.put("generateSpentAddressesFile", new Callable({ call: generate }))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.


log.error("Caught error during read: {}", error);
return {
error: error
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

var checksum;
try {
// False for always overwriting
writer = new java.io.FileWriter(file, false);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

});
}

API.put("mergeSpentAddresses", new Callable({ call: generate }))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

var defaultSpentFileName = "spentAddresses.txt";

// Log using logger of the ixi class
var log = org.slf4j.LoggerFactory.getLogger(iri.IXI.class);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@@ -0,0 +1,147 @@
var System = java.lang.System;

var spentAddressProvider = IOTA.spentAddressesProvider
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

return false;
}

return expectedChecksum !== checksumFromBytes(digest.digest());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@@ -0,0 +1,79 @@
var System = java.lang.System;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

amount: hashes.length,
fileName: fileName,
sizeInMb: new java.lang.Integer(file.length() / (1024 * 1024)),
checksum: checksum
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

while (line = targetReader.readLine()){
if (firstLine){
firstLine = false;
} else if (line.length() === 64){
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for (var i=0; i<files.length; i++){
var fileName = files[i];

var file = new java.io.File(fileName);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@@ -0,0 +1,79 @@
var System = java.lang.System;

var spentAddressProvider = IOTA.spentAddressesProvider
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

var digest = java.security.MessageDigest.getInstance("SHA-256");
for (var i=0; i<hashes.length; i++){
// Update with hash bytes
digest.update(hashes[i].bytes());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@@ -0,0 +1,79 @@
var System = java.lang.System;

var spentAddressProvider = IOTA.spentAddressesProvider
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Regression tests for import and export of the spent-addresses-db
2 participants