forked from Qortal/qortal
Added test to check website/data updates.
This commit is contained in:
parent
8c7f09c454
commit
b771544c5d
@ -25,6 +25,7 @@ import java.io.IOException;
|
|||||||
import java.nio.file.Files;
|
import java.nio.file.Files;
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
import java.nio.file.Paths;
|
import java.nio.file.Paths;
|
||||||
|
import java.util.Arrays;
|
||||||
|
|
||||||
import static org.junit.Assert.*;
|
import static org.junit.Assert.*;
|
||||||
|
|
||||||
@ -157,6 +158,50 @@ public class ArbitraryDataTests extends Common {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testUpdateResource() throws DataException, IOException {
|
||||||
|
try (final Repository repository = RepositoryManager.getRepository()) {
|
||||||
|
PrivateKeyAccount alice = Common.getTestAccount(repository, "alice");
|
||||||
|
String publicKey58 = Base58.encode(alice.getPublicKey());
|
||||||
|
String name = "TEST"; // Can be anything for this test
|
||||||
|
Service service = Service.WEBSITE; // Can be anything for this test
|
||||||
|
|
||||||
|
// Register the name to Alice
|
||||||
|
RegisterNameTransactionData transactionData = new RegisterNameTransactionData(TestTransaction.generateBase(alice), name, "");
|
||||||
|
TransactionUtils.signAndMint(repository, transactionData, alice);
|
||||||
|
|
||||||
|
// Create PUT transaction
|
||||||
|
Path path1 = Paths.get("src/test/resources/arbitrary/demo1");
|
||||||
|
this.createAndMintTxn(repository, publicKey58, path1, name, Method.PUT, service, alice);
|
||||||
|
|
||||||
|
// Now build the latest data state for this name
|
||||||
|
ArbitraryDataReader arbitraryDataReader1 = new ArbitraryDataReader(name, ResourceIdType.NAME, service);
|
||||||
|
arbitraryDataReader1.loadSynchronously(true);
|
||||||
|
Path initialLayerPath = arbitraryDataReader1.getFilePath();
|
||||||
|
ArbitraryDataDigest initialLayerDigest = new ArbitraryDataDigest(initialLayerPath);
|
||||||
|
initialLayerDigest.compute();
|
||||||
|
|
||||||
|
// Create PATCH transaction
|
||||||
|
Path path2 = Paths.get("src/test/resources/arbitrary/demo2");
|
||||||
|
this.createAndMintTxn(repository, publicKey58, path2, name, Method.PATCH, service, alice);
|
||||||
|
|
||||||
|
// Rebuild the latest state
|
||||||
|
ArbitraryDataReader arbitraryDataReader2 = new ArbitraryDataReader(name, ResourceIdType.NAME, service);
|
||||||
|
arbitraryDataReader2.loadSynchronously(false);
|
||||||
|
Path secondLayerPath = arbitraryDataReader2.getFilePath();
|
||||||
|
ArbitraryDataDigest secondLayerDigest = new ArbitraryDataDigest(secondLayerPath);
|
||||||
|
secondLayerDigest.compute();
|
||||||
|
|
||||||
|
// Ensure that the second state is different to the first state
|
||||||
|
assertFalse(Arrays.equals(initialLayerDigest.getHash(), secondLayerDigest.getHash()));
|
||||||
|
|
||||||
|
// Its directory hash should match the hash of demo2
|
||||||
|
ArbitraryDataDigest path2Digest = new ArbitraryDataDigest(path2);
|
||||||
|
path2Digest.compute();
|
||||||
|
assertEquals(path2Digest.getHash58(), secondLayerDigest.getHash58());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void createAndMintTxn(Repository repository, String publicKey58, Path path, String name,
|
private void createAndMintTxn(Repository repository, String publicKey58, Path path, String name,
|
||||||
Method method, Service service, PrivateKeyAccount account) throws DataException {
|
Method method, Service service, PrivateKeyAccount account) throws DataException {
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user