Skynet SDK Testing

tags: SDK

Instructions for testing the SDKs.

skynet-js

The following procedure should be done within the skynet-js repo.

  1. You may want to create a new branch to avoid committing the following changes.

  2. Create index.html in root with some buttons to trigger functions you want to test:

<html> <body> <input type="button" value="Download" id="download"/> <input type="file" id="mediaFile"> <input type="button" value="Upload" id="upload"/> <script type="application/javascript" src="./dist/main.js"></script> </body> </html>
  1. Add some click events for these buttons at the bottom of src/index.ts (don't commit this):
import { SkynetClient } from "./client"; const client = new SkynetClient("https://siasky.net"); const skylink = "CABqlFxQyimh292KJlqp-7HMA_vypPnSCoB-QZjzG5ObHw"; document.getElementById("download").addEventListener("click", function () { client.downloadFile(skylink); }); document.getElementById("upload").addEventListener("click", function () { const file = (<HTMLInputElement>document.getElementById('mediaFile')).files[0]; client.uploadFile(file); });
  1. Run
yarn add -D webpack webpack-cli
  1. Add the following webpack.config.js file:
module.exports = { mode: "development", entry: "./dist", output: { library: "skynet-js", libraryTarget: "umd", umdNamedDefine: true, }, target: "web", };
  1. yarn build

  2. yarn run webpack

  3. python3 -m http.server

  4. Attend
    http://localhost:8000/
    in your browser.

nodejs-skynet

  1. Make a test script, let's call it test.js:
const { SkynetClient } = require("./index.js"); const client = new SkynetClient(); async function uploadResponse() { const filename = "README.md"; try { console.log(filename); const skylink = await client.uploadFile(filename); console.log(skylink); } catch (error) { console.log(error); } } uploadResponse();
  1. node test.js

python-skynet

  1. Make a test script, let's call it test.py:
import siaskynet as skynet client = skynet.SkynetClient() filename = "tmp-91161-Kw39pPEcTxAZ-.json" skylink = client.upload_file(filename) print("Upload successful, skylink: " + skylink)
  1. pipenv run python test.py

go-skynet

  1. Make a test script in a subdirectory e.g. main/ with the main package:
package main

import (
	"fmt"
	skynet "github.com/NebulousLabs/go-skynet/v2"
)

// create a client
var client = skynet.NewCustom("http://localhost:9980", skynet.Options{})

func main() {
	// upload
	opts := skynet.DefaultUploadOptions
	opts.SkykeyName = "key_to_the_castle"
	skylink, err := client.UploadFile("./unencrypted.txt", opts)
	if err != nil {
		panic("Unable to upload: " + err.Error())
	}
	fmt.Printf("Upload successful, skylink: %v\n", skylink)

	// download
	err = client.DownloadFile("./encrypted.txt", skylink, skynet.DefaultDownloadOptions)
	if err != nil {
		panic("Something went wrong, please try again.\nError: " + err.Error())
	}
	fmt.Println("Download successful")
}
  1. go run main/main.go

See Also

Select a repo