Skip to content

Commit 0470d80

Browse files
committed
Added a testData
test data does not need init and it does not use WNFS
1 parent ec286ff commit 0470d80

File tree

6 files changed

+66
-2
lines changed

6 files changed

+66
-2
lines changed

android/build.gradle

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,9 @@ repositories {
6262
dependencies {
6363
//noinspection GradleDynamicVersion
6464
implementation "com.facebook.react:react-native:+" // From node_modules
65-
implementation 'com.github.functionland:fula-build-aar:1.9.0' // From jitpack.io
65+
implementation 'com.github.functionland:fula-build-aar:1.11.2' // From jitpack.io
6666
implementation 'com.github.functionland:wnfs-build-aar:v1.4.1' // From jitpack.io
6767
implementation 'commons-io:commons-io:20030203.000550'
68+
implementation 'commons-codec:commons-codec:1.15'
6869
// implementation files('mobile.aar')
6970
}

android/src/main/java/land/fx/fula/FulaModule.java

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
import com.facebook.react.module.annotations.ReactModule;
1414

1515
import org.apache.commons.io.FileUtils;
16+
import org.apache.commons.codec.binary.Base32;
1617
import org.jetbrains.annotations.Contract;
1718

1819
import java.io.File;
@@ -23,6 +24,7 @@
2324
import java.security.InvalidKeyException;
2425
import java.security.NoSuchAlgorithmException;
2526
import java.util.Arrays;
27+
import java.util.Random;
2628

2729
import javax.crypto.BadPaddingException;
2830
import javax.crypto.IllegalBlockSizeException;
@@ -1390,4 +1392,35 @@ public void reboot(Promise promise) {
13901392
});
13911393
}
13921394

1395+
@ReactMethod
1396+
public void testData(String identityString, String bloxAddr, Promise promise) {
1397+
try {
1398+
byte[] identity = toByte(identityString);
1399+
byte[] peerIdByte = this.newClientInternal(identity, "", bloxAddr, "", true, true, true);
1400+
1401+
String peerIdReturned = Arrays.toString(peerIdByte);
1402+
Log.d("ReactNative", "newClient peerIdReturned= " + peerIdReturned);
1403+
String peerId = this.fula.id();
1404+
Log.d("ReactNative", "newClient peerId= " + peerId);
1405+
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};
1406+
1407+
byte[] key = this.fula.put(bytes, 85);
1408+
Log.d("ReactNative", "testData put result string="+Arrays.toString(key));
1409+
1410+
byte[] value = this.fula.get(key);
1411+
Log.d("ReactNative", "testData get result string="+Arrays.toString(value));
1412+
1413+
this.fula.push(key);
1414+
//this.fula.flush();
1415+
1416+
byte[] fetchedVal = this.fula.get(key);
1417+
this.fula.pull(key);
1418+
1419+
promise.resolve(Arrays.toString(fetchedVal));
1420+
} catch (Exception e) {
1421+
Log.d("ReactNative", "ERROR:" + e.getMessage());
1422+
promise.reject(e);
1423+
}
1424+
}
1425+
13931426
}

example/android/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
buildscript {
44
ext {
5-
minSdkVersion = 26
5+
minSdkVersion = 30
66
compileSdkVersion = 31
77
targetSdkVersion = 31
88
ndkVersion = '25.1.8937393'

example/src/App.tsx

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,26 @@ const App = () => {
131131

132132
<Button
133133
title={inprogress ? 'Putting & Getting...' : 'Test'}
134+
onPress={async () => {
135+
try {
136+
fula
137+
.testData(privateKey.toString(), bloxAddr)
138+
.then((res) => {
139+
console.log('tested');
140+
console.log(res);
141+
})
142+
.catch((e) => {
143+
console.log('test failed');
144+
console.log(e);
145+
});
146+
147+
} catch (e) {}
148+
}}
149+
color={inprogress ? 'green' : 'blue'}
150+
/>
151+
152+
<Button
153+
title={inprogress ? 'Putting & Getting...' : 'Write WNFS'}
134154
onPress={async () => {
135155
try {
136156
if (initComplete) {

src/interfaces/fulaNativeModule.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ interface FulaNativeModule {
4747

4848
shutdown: () => Promise<void>;
4949

50+
testData: (identity: string, bloxAddr: string) => Promise<string>;
51+
5052
//Blockchain related functions
5153
createAccount: (seed: string) => Promise<string>;
5254
checkAccountExists: (account: string) => Promise<string>;

src/protocols/fula.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,14 @@ export const push = (): Promise<string> => {
118118
return Fula.push();
119119
};
120120

121+
//This method sends some test data to backedn
122+
export const testData = (
123+
identity: string,
124+
bloxAddr: string
125+
): Promise<string> => {
126+
return Fula.testData(identity, bloxAddr);
127+
};
128+
121129
/**
122130
* Put stores the given key value onto the local datastore.
123131
// The key must be a valid ipld.Link and the value must be the valid encoded ipld.Node corresponding

0 commit comments

Comments
 (0)