Skip to content

Commit

Permalink
Added a testData
Browse files Browse the repository at this point in the history
test data does not need init and it does not use WNFS
  • Loading branch information
ehsan6sha committed Jul 8, 2023
1 parent ec286ff commit 0470d80
Show file tree
Hide file tree
Showing 6 changed files with 66 additions and 2 deletions.
3 changes: 2 additions & 1 deletion android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,9 @@ repositories {
dependencies {
//noinspection GradleDynamicVersion
implementation "com.facebook.react:react-native:+" // From node_modules
implementation 'com.github.functionland:fula-build-aar:1.9.0' // From jitpack.io
implementation 'com.github.functionland:fula-build-aar:1.11.2' // From jitpack.io
implementation 'com.github.functionland:wnfs-build-aar:v1.4.1' // From jitpack.io
implementation 'commons-io:commons-io:20030203.000550'
implementation 'commons-codec:commons-codec:1.15'
// implementation files('mobile.aar')
}
33 changes: 33 additions & 0 deletions android/src/main/java/land/fx/fula/FulaModule.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import com.facebook.react.module.annotations.ReactModule;

import org.apache.commons.io.FileUtils;
import org.apache.commons.codec.binary.Base32;
import org.jetbrains.annotations.Contract;

import java.io.File;
Expand All @@ -23,6 +24,7 @@
import java.security.InvalidKeyException;
import java.security.NoSuchAlgorithmException;
import java.util.Arrays;
import java.util.Random;

import javax.crypto.BadPaddingException;
import javax.crypto.IllegalBlockSizeException;
Expand Down Expand Up @@ -1390,4 +1392,35 @@ public void reboot(Promise promise) {
});
}

@ReactMethod
public void testData(String identityString, String bloxAddr, Promise promise) {
try {
byte[] identity = toByte(identityString);
byte[] peerIdByte = this.newClientInternal(identity, "", bloxAddr, "", true, true, true);

String peerIdReturned = Arrays.toString(peerIdByte);
Log.d("ReactNative", "newClient peerIdReturned= " + peerIdReturned);
String peerId = this.fula.id();
Log.d("ReactNative", "newClient peerId= " + peerId);
byte[] bytes = {1, 85, 18, 32, 11, -31, 75, -78, -109, 11, -111, 97, -47, -78, -22, 84, 39, -117, -64, -70, -91, 55, -23, -80, 116, -123, -97, -26, 126, -70, -76, 35, 54, -106, 55, -9};

byte[] key = this.fula.put(bytes, 85);
Log.d("ReactNative", "testData put result string="+Arrays.toString(key));

byte[] value = this.fula.get(key);
Log.d("ReactNative", "testData get result string="+Arrays.toString(value));

this.fula.push(key);
//this.fula.flush();

byte[] fetchedVal = this.fula.get(key);
this.fula.pull(key);

promise.resolve(Arrays.toString(fetchedVal));
} catch (Exception e) {
Log.d("ReactNative", "ERROR:" + e.getMessage());
promise.reject(e);
}
}

}
2 changes: 1 addition & 1 deletion example/android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

buildscript {
ext {
minSdkVersion = 26
minSdkVersion = 30
compileSdkVersion = 31
targetSdkVersion = 31
ndkVersion = '25.1.8937393'
Expand Down
20 changes: 20 additions & 0 deletions example/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,26 @@ const App = () => {

<Button
title={inprogress ? 'Putting & Getting...' : 'Test'}
onPress={async () => {
try {
fula
.testData(privateKey.toString(), bloxAddr)
.then((res) => {
console.log('tested');
console.log(res);
})
.catch((e) => {
console.log('test failed');
console.log(e);
});

} catch (e) {}
}}
color={inprogress ? 'green' : 'blue'}
/>

<Button
title={inprogress ? 'Putting & Getting...' : 'Write WNFS'}
onPress={async () => {
try {
if (initComplete) {
Expand Down
2 changes: 2 additions & 0 deletions src/interfaces/fulaNativeModule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ interface FulaNativeModule {

shutdown: () => Promise<void>;

testData: (identity: string, bloxAddr: string) => Promise<string>;

//Blockchain related functions
createAccount: (seed: string) => Promise<string>;
checkAccountExists: (account: string) => Promise<string>;
Expand Down
8 changes: 8 additions & 0 deletions src/protocols/fula.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,14 @@ export const push = (): Promise<string> => {
return Fula.push();
};

//This method sends some test data to backedn
export const testData = (
identity: string,
bloxAddr: string
): Promise<string> => {
return Fula.testData(identity, bloxAddr);
};

/**
* Put stores the given key value onto the local datastore.
// The key must be a valid ipld.Link and the value must be the valid encoded ipld.Node corresponding
Expand Down

0 comments on commit 0470d80

Please sign in to comment.