Skip to content
This repository has been archived by the owner on Jan 10, 2023. It is now read-only.

Commit

Permalink
jest and muck testing added to project for unit testing
Browse files Browse the repository at this point in the history
  • Loading branch information
dorbor committed Sep 22, 2022
1 parent ef77c74 commit 211953a
Show file tree
Hide file tree
Showing 9 changed files with 6,171 additions and 16 deletions.
1 change: 0 additions & 1 deletion app.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,3 @@ app.listen(
)
);


9 changes: 6 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
"description": "",
"main": "app.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"dev": "nodemon app"
"dev": "nodemon app",
"test": "jest --watchAll"
},
"keywords": [],
"author": "",
Expand All @@ -17,6 +17,7 @@
"cors": "^2.8.5",
"express": "^4.18.1",
"jsonwebtoken": "^8.5.1",
"mockjs": "^1.1.0",
"mongoose": "^6.3.4",
"morgan": "^1.10.0",
"qs": "^6.11.0",
Expand All @@ -26,6 +27,8 @@
"xumm-sdk": "^1.3.4"
},
"devDependencies": {
"nodemon": "^2.0.19"
"jest": "^29.0.3",
"nodemon": "^2.0.19",
"supertest": "^6.2.4"
}
}
42 changes: 42 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# XUMM-XRPL Proof of Concept

This repo demonstrates a Proof of Concept application for sending offers to the XRPL Decentralised Exchange (DEX) using the XUMM app for authentication.

## Installation

The application itself is a node js application so make sure to have node js installed in your environment. To install the requirements run:

```bash
yarn install
```

The script to demo the application is written in python. Ensure you have python3 installed in your (ideally virtual) environment and run:

```bash
pip install -r requirements.txt
```

## Run the demo

First you need to create a `.env` file in the root directory with the following keys:

* `NODE_ENV`: Used by the node server. If this is set to 'development', middleware logging will be done.
* `API_KEY`: XUMM Developer Application API Key. Used by the node server to communicate with XUMM.
* `API_SECRET`: XUMM Developer Application API Secret. Used by the node server to communicate with XUMM.
* `WALLET_ADDRESS`: Used by the python code to know which wallet to transact under.

Then, open two terminals. In the first terminal run:

```bash
yarn dev
```

This will start the development server which will respond to requests that our python script will send to it.

In the second terminal run:

```bash
python -m scripts.poc_demo
```

This will send two requests to our server. The first will open your default web browser displaying a QR code which you must scan with your XUMM app and sign the transaction to retrieve a user token. This user token will then be used in the second request in order to send a push notification to the user to sign the offer transaction that will be sent to the DEX instead of having them scan a QR code. Ensure your XUMM app has access to the wallet you are using to perform the transaction.
33 changes: 33 additions & 0 deletions readme.md~Stashed changes
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# Connect to xumm sdk

set 1) make sure you have yarn package manager install
step 3) clone repo with: git clone (repo)
step 3) in your terminal, run 'yarn install' // to istall all the require packages
step 4) in your terminal, run 'yarn dev'


step 5) use postman to submit data to the below routes

localhost:4000/api/v1/xrp/test (for testing)
whatever data you want to pass
localhost:4000/api/v1/xrp/createdexoffer (create offer on xrpl lerger production server)
json data

{
"address": "---wallet address---",
"weWant": {
"currency": "currency",
"value": "value"
},
"weSpend": {
"currency": "currency",
"value": "value"
}
}


1)get user token without cash transaction -->
# visit : localhost:4000/api/v1/xrp/gettoken
# you will get a qrcode,
# scan to sign request
# user token will be generated on the fly
2 changes: 1 addition & 1 deletion routes/v1/xrp.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ router.route("/createOffer").post(createOffer);

// for testing
// api/v1/xrp/test
router.route("/test").post(test);
router.route("/test").get(test);


module.exports = router;
14 changes: 14 additions & 0 deletions test/xrp.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
const app = require('../app');
const request = require('supertest');
const axios = require('axios');
const { JsonWebTokenError } = require('jsonwebtoken');

jest.mock("axios")

describe('xrp testing', () => {
it('XRPL create dex offer', () => {
const resp = "offer created sussefully on the xrpl lerger"
axios.get.mockResolvedValue(resp)
return expect(resp).toEqual(resp)
})
})
19 changes: 19 additions & 0 deletions test/xumm.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
const request = require('supertest');
const axios = require('axios');

jest.mock("axios")

describe('xrp testing', () => {

it('Get User token ', () => {
const userToken = {"user_token": "74d-2641f0398-8562-3782-24ffe3843c52" }
axios.get.mockResolvedValue(userToken)
return expect(userToken).toEqual(userToken)
})

it('Send Xrp via Xumm wallet ', () => {
const status = {"status": "xrp send successfully" }
axios.post.mockResolvedValue(status)
return expect(status).toEqual(status)
})
})
Loading

0 comments on commit 211953a

Please sign in to comment.