Compare commits
33 Commits
no-host-mo
...
lash/check
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
a3294c33ac | ||
|
f3070a0172
|
|||
|
a9018f7666
|
|||
|
03215ded11
|
|||
|
0520a84b9e
|
|||
|
d163b50ca7
|
|||
|
e2892a933e
|
|||
|
|
e5b1352970 | ||
|
|
89b90da5d2 | ||
|
9624bb3623
|
|||
|
6f88e05176
|
|||
|
67388e0d4f
|
|||
|
9b30fffaf8
|
|||
|
5c7ef41323
|
|||
|
e03b932587
|
|||
|
23679a6d7e
|
|||
| 9607994c31 | |||
| 0da617d29e | |||
| 56bcad16a5 | |||
| 77d9936e39 | |||
|
|
72aeefc78b | ||
|
|
fab9b0c520
|
||
|
43f32eab61
|
|||
|
eace7969b8
|
|||
| 9566f8c8e2 | |||
|
007d7a5121
|
|||
| fc20849aff | |||
| 1605e53216 | |||
| 200fdf0e3c | |||
| 022db04198 | |||
| 1c17048981 | |||
|
|
befcb0e0fb
|
||
|
|
3c2731b487
|
3
.gitignore
vendored
3
.gitignore
vendored
@@ -8,3 +8,6 @@ gmon.out
|
||||
*.egg-info
|
||||
dist/
|
||||
build/
|
||||
**/*sqlite
|
||||
**/.nyc_output
|
||||
**/coverage
|
||||
|
||||
2
apps/cic-meta/.gitignore
vendored
2
apps/cic-meta/.gitignore
vendored
@@ -3,3 +3,5 @@ dist
|
||||
dist-web
|
||||
dist-server
|
||||
scratch
|
||||
coverage
|
||||
.nyc_output
|
||||
|
||||
@@ -3,17 +3,38 @@
|
||||
variables:
|
||||
APP_NAME: cic-meta
|
||||
DOCKERFILE_PATH: $APP_NAME/docker/Dockerfile
|
||||
IMAGE_TAG: $CI_REGISTRY_IMAGE/$APP_NAME:unittest-$CI_COMMIT_SHORT_SHA
|
||||
|
||||
.cic_meta_changes_target:
|
||||
rules:
|
||||
- changes:
|
||||
- $CONTEXT/$APP_NAME/*
|
||||
- if: $CI_PIPELINE_SOURCE == "merge_request_event"
|
||||
# - changes:
|
||||
# - $CONTEXT/$APP_NAME/*
|
||||
- when: always
|
||||
|
||||
build-mr-cic-meta:
|
||||
cic-meta-build-mr:
|
||||
stage: build
|
||||
extends:
|
||||
- .cic_meta_variables
|
||||
- .cic_meta_changes_target
|
||||
script:
|
||||
- mkdir -p /kaniko/.docker
|
||||
- echo "{\"auths\":{\"$CI_REGISTRY\":{\"username\":\"$CI_REGISTRY_USER\",\"password\":\"$CI_REGISTRY_PASSWORD\"}}}" > "/kaniko/.docker/config.json"
|
||||
# - /kaniko/executor --context $CONTEXT --dockerfile $DOCKERFILE_PATH $KANIKO_CACHE_ARGS --destination $IMAGE_TAG
|
||||
- /kaniko/executor --context $CONTEXT --dockerfile $DOCKERFILE_PATH $KANIKO_CACHE_ARGS --destination $IMAGE_TAG
|
||||
|
||||
test-mr-cic-meta:
|
||||
extends:
|
||||
- .cic_meta_changes_target
|
||||
- .py_build_merge_request
|
||||
- .cic_meta_variables
|
||||
- .cic_meta_changes_target
|
||||
stage: test
|
||||
image: $IMAGE_TAG
|
||||
script:
|
||||
- cd /tmp/src/cic-meta
|
||||
- npm install --dev
|
||||
- npm run test
|
||||
- npm run test:coverage
|
||||
needs: ["cic-meta-build-mr"]
|
||||
|
||||
build-push-cic-meta:
|
||||
extends:
|
||||
|
||||
@@ -4,29 +4,28 @@ WORKDIR /tmp/src/cic-meta
|
||||
|
||||
RUN apk add --no-cache postgresql bash
|
||||
|
||||
COPY cic-meta/package.json \
|
||||
./
|
||||
|
||||
# required to build the cic-client-meta module
|
||||
COPY cic-meta/src/ src/
|
||||
COPY cic-meta/tests/ tests/
|
||||
COPY cic-meta/scripts/ scripts/
|
||||
|
||||
# copy the dependencies
|
||||
COPY cic-meta/package.json .
|
||||
COPY cic-meta/tsconfig.json .
|
||||
COPY cic-meta/webpack.config.js .
|
||||
|
||||
RUN npm install
|
||||
|
||||
# see exports_dir gpg.ini
|
||||
COPY cic-meta/tests/ tests/
|
||||
COPY cic-meta/tests/*.asc /root/pgp/
|
||||
RUN alias tsc=node_modules/typescript/bin/tsc
|
||||
|
||||
|
||||
# copy runtime configs
|
||||
COPY cic-meta/.config/ /usr/local/etc/cic-meta/
|
||||
# COPY cic-meta/scripts/server/initdb/server.postgres.sql /usr/local/share/cic-meta/sql/server.sql
|
||||
|
||||
# db migrations
|
||||
COPY cic-meta/docker/db.sh ./db.sh
|
||||
RUN chmod 755 ./db.sh
|
||||
|
||||
#RUN alias ts-node=/tmp/src/cic-meta/node_modules/ts-node/dist/bin.js
|
||||
#ENTRYPOINT [ "./node_modules/ts-node/dist/bin.js", "./scripts/server/server.ts" ]
|
||||
|
||||
RUN alias tsc=node_modules/typescript/bin/tsc
|
||||
COPY cic-meta/docker/start_server.sh ./start_server.sh
|
||||
RUN chmod 755 ./start_server.sh
|
||||
ENTRYPOINT ["sh", "./start_server.sh"]
|
||||
|
||||
2362
apps/cic-meta/package-lock.json
generated
2362
apps/cic-meta/package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@@ -11,6 +11,7 @@
|
||||
"preferGlobal": true,
|
||||
"scripts": {
|
||||
"test": "mocha -r node_modules/node-localstorage/register -r ts-node/register tests/*.ts",
|
||||
"test:coverage": "nyc mocha tests/*.ts --timeout 3000 --check-coverage=true",
|
||||
"build": "node_modules/typescript/bin/tsc -d --outDir dist src/index.ts",
|
||||
"build-server": "tsc -d --outDir dist-server scripts/server/*.ts",
|
||||
"pack": "node_modules/typescript/bin/tsc -d --outDir dist && webpack",
|
||||
@@ -34,7 +35,9 @@
|
||||
"devDependencies": {
|
||||
"@types/mocha": "^8.0.3",
|
||||
"mocha": "^8.2.0",
|
||||
"nock": "^13.1.0",
|
||||
"node-localstorage": "^2.1.6",
|
||||
"nyc": "^15.1.0",
|
||||
"ts-node": "^9.0.0",
|
||||
"typescript": "^4.0.5",
|
||||
"webpack": "^5.4.0",
|
||||
@@ -50,5 +53,26 @@
|
||||
"license": "GPL-3.0-or-later",
|
||||
"engines": {
|
||||
"node": ">=14.16.1"
|
||||
},
|
||||
"nyc": {
|
||||
"include": [
|
||||
"src/**/*.ts"
|
||||
],
|
||||
"extension": [
|
||||
".ts"
|
||||
],
|
||||
"require": [
|
||||
"ts-node/register"
|
||||
],
|
||||
"reporter": [
|
||||
"text",
|
||||
"html"
|
||||
],
|
||||
"sourceMap": true,
|
||||
"instrument": true,
|
||||
"branches": ">80",
|
||||
"lines": ">80",
|
||||
"functions": ">80",
|
||||
"statements": ">80"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -204,7 +204,7 @@ async function processRequest(req, res) {
|
||||
}
|
||||
|
||||
if (content === undefined) {
|
||||
console.error('empty onctent', data);
|
||||
console.error('empty content', data);
|
||||
res.writeHead(400, {"Content-Type": "text/plain"});
|
||||
res.end();
|
||||
return;
|
||||
|
||||
@@ -9,7 +9,7 @@ class Custom extends Syncable implements Addressable {
|
||||
super('', v);
|
||||
Custom.toKey(name).then((cid) => {
|
||||
this.id = cid;
|
||||
this.value = v;
|
||||
this.name = name;
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -100,13 +100,15 @@ class Meta {
|
||||
identifier = await User.toKey(name);
|
||||
} else if (type === 'phone') {
|
||||
identifier = await Phone.toKey(name);
|
||||
} else {
|
||||
} else if (type === 'custom') {
|
||||
identifier = await Custom.toKey(name);
|
||||
} else {
|
||||
identifier = await Custom.toKey(name, type);
|
||||
}
|
||||
return identifier;
|
||||
}
|
||||
|
||||
private wrap(syncable: Syncable): Promise<Envelope> {
|
||||
wrap(syncable: Syncable): Promise<Envelope> {
|
||||
return new Promise<Envelope>(async (resolve, reject) => {
|
||||
syncable.setSigner(this.signer);
|
||||
syncable.onwrap = async (env) => {
|
||||
|
||||
49
apps/cic-meta/tests/custom.ts
Normal file
49
apps/cic-meta/tests/custom.ts
Normal file
@@ -0,0 +1,49 @@
|
||||
import * as assert from 'assert';
|
||||
import {Custom} from "../src";
|
||||
|
||||
const testName = 'areas';
|
||||
const testObject = {
|
||||
area: ['Nairobi', 'Mombasa', 'Kilifi']
|
||||
}
|
||||
const testNameKey = '8f3da0c90ba2b89ff217da96f6088cbaf987a1b58bc33c3a5e526e53cec7cfed';
|
||||
const testIdentifier = ':cic.area'
|
||||
const testIdentifierKey = 'da6194e6f33726546e82c328df4c120b844d6427859156518bd600765bf8b2b7';
|
||||
|
||||
describe('custom', () => {
|
||||
|
||||
context('with predefined data', () => {
|
||||
it('should create a custom object', () => {
|
||||
const custom = new Custom(testName, testObject);
|
||||
setTimeout(() => {
|
||||
assert.strictEqual(custom.name, testName);
|
||||
assert.deepStrictEqual(custom.m.data, testObject);
|
||||
assert.strictEqual(custom.key(), testNameKey)
|
||||
}, 0);
|
||||
});
|
||||
});
|
||||
|
||||
context('without predefined data', () => {
|
||||
it('should create a custom object', () => {
|
||||
const custom = new Custom(testName);
|
||||
setTimeout(() => {
|
||||
assert.strictEqual(custom.name, testName);
|
||||
assert.deepStrictEqual(custom.m.data, {});
|
||||
assert.strictEqual(custom.key(), testNameKey)
|
||||
}, 0);
|
||||
});
|
||||
});
|
||||
|
||||
describe('#toKey()', () => {
|
||||
context('without a custom identifier', () => {
|
||||
it('should generate a key from the custom name', async () => {
|
||||
assert.strictEqual(await Custom.toKey(testName), testNameKey);
|
||||
});
|
||||
});
|
||||
|
||||
context('with a custom identifier', () => {
|
||||
it('should generate a key from the custom name with a custom identifier', async () => {
|
||||
assert.strictEqual(await Custom.toKey(testName, testIdentifier), testIdentifierKey);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
176
apps/cic-meta/tests/meta.ts
Normal file
176
apps/cic-meta/tests/meta.ts
Normal file
@@ -0,0 +1,176 @@
|
||||
import * as assert from 'assert';
|
||||
import * as fs from 'fs';
|
||||
const nock = require('nock');
|
||||
import {Meta} from "../src";
|
||||
import {getResponse, metaData, networkErrorResponse, notFoundResponse, putResponse} from "./response";
|
||||
import {Syncable} from "@cicnet/crdt-meta";
|
||||
|
||||
const metaUrl = 'https://meta.dev.grassrootseconomics.net';
|
||||
const testAddress = '0xc1912fee45d61c87cc5ea59dae31190fffff232d';
|
||||
const testAddressKey = 'a51472cb4df63b199a4de01335b1b4d1bbee27ff4f03340aa1d592f26c6acfe2';
|
||||
const testPhone = '+254123456789';
|
||||
const testPhoneKey = 'be3cc8212b7eb57c6217ddd42230bd8ccd2f01382bf8c1c77d3a683fa5a9bb16';
|
||||
const testName = 'areas'
|
||||
const testNameKey = '8f3da0c90ba2b89ff217da96f6088cbaf987a1b58bc33c3a5e526e53cec7cfed';
|
||||
const testIdentifier = ':cic.area'
|
||||
const testIdentifierKey = 'da6194e6f33726546e82c328df4c120b844d6427859156518bd600765bf8b2b7';
|
||||
|
||||
function readFile(filename) {
|
||||
if(!fs.existsSync(filename)) {
|
||||
console.error(`File ${filename} not found`);
|
||||
return;
|
||||
}
|
||||
return fs.readFileSync(filename, {encoding: 'utf8', flag: 'r'});
|
||||
}
|
||||
|
||||
const privateKey = readFile('./privatekeys.asc');
|
||||
|
||||
describe('meta', () => {
|
||||
beforeEach(() => {
|
||||
nock(metaUrl)
|
||||
.get(`/${testAddressKey}`)
|
||||
.reply(200, getResponse);
|
||||
|
||||
nock(metaUrl)
|
||||
.get(`/${testPhoneKey}`)
|
||||
.reply(200, getResponse);
|
||||
|
||||
nock(metaUrl)
|
||||
.get(`/${testAddress}`)
|
||||
.reply(404);
|
||||
|
||||
nock(metaUrl)
|
||||
.get(`/${testIdentifier}`)
|
||||
.replyWithError(networkErrorResponse);
|
||||
|
||||
nock(metaUrl)
|
||||
.put(`/${testAddressKey}`)
|
||||
.reply(200, putResponse);
|
||||
|
||||
nock(metaUrl)
|
||||
.put(`/${testAddress}`)
|
||||
.reply(404);
|
||||
|
||||
nock(metaUrl)
|
||||
.post('/post')
|
||||
.reply(500);
|
||||
});
|
||||
|
||||
describe('#get()', () => {
|
||||
it('should fetch data from the meta service', async () => {
|
||||
const account = await Meta.get(testAddressKey, metaUrl);
|
||||
assert.strictEqual(account.toJSON(account), getResponse.payload);
|
||||
});
|
||||
|
||||
context('if item is not found', () => {
|
||||
it('should respond with an error', async () => {
|
||||
const account = await Meta.get(testAddress, metaUrl);
|
||||
assert.strictEqual(account, `404: Not Found`);
|
||||
});
|
||||
});
|
||||
|
||||
context('in case of network error', () => {
|
||||
it('should respond with an error', async () => {
|
||||
const account = await Meta.get(testIdentifier, metaUrl);
|
||||
assert.strictEqual(account, `Request to ${metaUrl}/${testIdentifier} failed. Connection error.`);
|
||||
});
|
||||
});
|
||||
})
|
||||
|
||||
describe('#set()', () => {
|
||||
context('object data', () => {
|
||||
it('should set data to the meta server', () => {
|
||||
const meta = new Meta(metaUrl, privateKey);
|
||||
meta.onload = async (status) => {
|
||||
const response = await meta.set(testAddressKey, metaData);
|
||||
assert.strictEqual(response, `${putResponse.status}: ${putResponse.statusText}`);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
context('string data', () => {
|
||||
it('should set data to the meta server', () => {
|
||||
const meta = new Meta(metaUrl, privateKey);
|
||||
meta.onload = async (status) => {
|
||||
const response = await meta.set(testPhoneKey, testAddress);
|
||||
assert.strictEqual(response, `${putResponse.status}: ${putResponse.statusText}`);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
context('in case of network error', () => {
|
||||
it('should respond with an error', () => {
|
||||
const meta = new Meta(metaUrl, privateKey);
|
||||
meta.onload = async (status) => {
|
||||
const response = await meta.set(testIdentifier, metaData);
|
||||
assert.strictEqual(response, `Request to ${metaUrl}/${testIdentifier} failed. Connection error.`);
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('#updateMeta()', () => {
|
||||
it('should update data in the meta server', async () => {
|
||||
const syncable = new Syncable(testAddressKey, metaData);
|
||||
const meta = new Meta(metaUrl, privateKey);
|
||||
meta.onload = async (status) => {
|
||||
const response = await meta.updateMeta(syncable, testAddressKey);
|
||||
assert.strictEqual(response, putResponse);
|
||||
}
|
||||
});
|
||||
|
||||
context('if item is not found', () => {
|
||||
it('should respond with an error', () => {
|
||||
const syncable = new Syncable(testAddress, metaData);
|
||||
const meta = new Meta(metaUrl, privateKey);
|
||||
meta.onload = async (status) => {
|
||||
const response = await meta.updateMeta(syncable, testAddress);
|
||||
assert.strictEqual(response, notFoundResponse);
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('#wrap()', () => {
|
||||
it('should sign a syncable object', function () {
|
||||
const syncable = new Syncable(testAddressKey, metaData);
|
||||
const meta = new Meta(metaUrl, privateKey);
|
||||
meta.onload = async (status) => {
|
||||
const response = await meta.wrap(syncable);
|
||||
assert.strictEqual(response.toJSON(), getResponse);
|
||||
}
|
||||
});
|
||||
})
|
||||
|
||||
describe('#getIdentifier()', () => {
|
||||
context('without type', () => {
|
||||
it('should return an identifier', async () => {
|
||||
assert.strictEqual(await Meta.getIdentifier(testName), testNameKey);
|
||||
});
|
||||
});
|
||||
|
||||
context('with user type', () => {
|
||||
it('should return an identifier', async () => {
|
||||
assert.strictEqual(await Meta.getIdentifier(testAddress, 'user'), testAddressKey);
|
||||
});
|
||||
});
|
||||
|
||||
context('with phone type', () => {
|
||||
it('should return an identifier', async () => {
|
||||
assert.strictEqual(await Meta.getIdentifier(testPhone, 'phone'), testPhoneKey);
|
||||
});
|
||||
});
|
||||
|
||||
context('with custom type', () => {
|
||||
it('should return an identifier', async () => {
|
||||
assert.strictEqual(await Meta.getIdentifier(testName, 'custom'), testNameKey);
|
||||
});
|
||||
});
|
||||
|
||||
context('with unrecognised type', () => {
|
||||
it('should return an identifier', async () => {
|
||||
assert.strictEqual(await Meta.getIdentifier(testName, testIdentifier), testIdentifierKey);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
24
apps/cic-meta/tests/phone.ts
Normal file
24
apps/cic-meta/tests/phone.ts
Normal file
@@ -0,0 +1,24 @@
|
||||
import * as assert from 'assert';
|
||||
import {Phone} from "../src";
|
||||
|
||||
const testAddress = '0xc1912fee45d61c87cc5ea59dae31190fffff232d';
|
||||
const testPhone = '+254123456789';
|
||||
const testPhoneKey = 'be3cc8212b7eb57c6217ddd42230bd8ccd2f01382bf8c1c77d3a683fa5a9bb16';
|
||||
|
||||
describe('phone', () => {
|
||||
|
||||
it('should create a phone object', () => {
|
||||
const phone = new Phone(testAddress, testPhone);
|
||||
setTimeout(() => {
|
||||
assert.strictEqual(phone.address, testAddress);
|
||||
assert.strictEqual(phone.m.data.msisdn, testPhone);
|
||||
assert.strictEqual(phone.key(), testPhoneKey)
|
||||
}, 0);
|
||||
});
|
||||
|
||||
describe('#toKey()', () => {
|
||||
it('should generate a key from the phone number', async () => {
|
||||
assert.strictEqual(await Phone.toKey(testPhone), testPhoneKey);
|
||||
});
|
||||
});
|
||||
});
|
||||
79
apps/cic-meta/tests/response.ts
Normal file
79
apps/cic-meta/tests/response.ts
Normal file
File diff suppressed because one or more lines are too long
54
apps/cic-meta/tests/user.ts
Normal file
54
apps/cic-meta/tests/user.ts
Normal file
@@ -0,0 +1,54 @@
|
||||
import * as assert from 'assert';
|
||||
|
||||
import { User } from "../src";
|
||||
|
||||
const testAddress = '0xc1912fee45d61c87cc5ea59dae31190fffff232d';
|
||||
const testAddressKey = 'a51472cb4df63b199a4de01335b1b4d1bbee27ff4f03340aa1d592f26c6acfe2';
|
||||
const testUser = {
|
||||
user: {
|
||||
firstName: 'Test',
|
||||
lastName: 'User'
|
||||
}
|
||||
}
|
||||
|
||||
describe('user', () => {
|
||||
|
||||
context('without predefined data', () => {
|
||||
it('should create a user object', () => {
|
||||
const user = new User(testAddress);
|
||||
setTimeout(() => {
|
||||
assert.strictEqual(user.address, testAddress);
|
||||
assert.strictEqual(user.key(), testAddressKey);
|
||||
assert.strictEqual(user.m.data.user.firstName, '');
|
||||
assert.strictEqual(user.m.data.user.lastName, '');
|
||||
}, 0);
|
||||
});
|
||||
});
|
||||
|
||||
context('with predefined data', () => {
|
||||
it('should create a user object', () => {
|
||||
const user = new User(testAddress, testUser);
|
||||
setTimeout(() => {
|
||||
assert.strictEqual(user.address, testAddress);
|
||||
assert.strictEqual(user.key(), testAddressKey);
|
||||
assert.strictEqual(user.m.data.user.firstName, testUser.user.firstName);
|
||||
assert.strictEqual(user.m.data.user.lastName, testUser.user.lastName);
|
||||
}, 0);
|
||||
});
|
||||
});
|
||||
|
||||
describe('#setName()', () => {
|
||||
it('should set user\'s names to metadata', () => {
|
||||
const user = new User(testAddress);
|
||||
user.setName(testUser.user.firstName, testUser.user.lastName);
|
||||
assert.strictEqual(user.m.data.user.firstName, testUser.user.firstName);
|
||||
assert.strictEqual(user.m.data.user.lastName, testUser.user.lastName);
|
||||
});
|
||||
});
|
||||
|
||||
describe('#toKey()', () => {
|
||||
it('should generate a key from the user\'s address', async () => {
|
||||
assert.strictEqual(await User.toKey(testAddress), testAddressKey);
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -2,7 +2,7 @@
|
||||
"compilerOptions": {
|
||||
"baseUrl": ".",
|
||||
"outDir": "./dist.browser",
|
||||
"target": "es5",
|
||||
"target": "es2015",
|
||||
"module": "commonjs",
|
||||
"moduleResolution": "node",
|
||||
"lib": ["es2016", "dom", "es5"],
|
||||
|
||||
@@ -5,6 +5,7 @@ LOCALE_PATH=/usr/src/cic-ussd/var/lib/locale/
|
||||
MAX_BODY_LENGTH=1024
|
||||
PASSWORD_PEPPER=QYbzKff6NhiQzY3ygl2BkiKOpER8RE/Upqs/5aZWW+I=
|
||||
SERVICE_CODE=*483*46#,*483*061#,*384*96#
|
||||
SUPPORT_PHONE_NUMBER=0757628885
|
||||
|
||||
[phone_number]
|
||||
REGION=KE
|
||||
|
||||
@@ -5,6 +5,7 @@ LOCALE_PATH=var/lib/locale/
|
||||
MAX_BODY_LENGTH=1024
|
||||
PASSWORD_PEPPER=QYbzKff6NhiQzY3ygl2BkiKOpER8RE/Upqs/5aZWW+I=
|
||||
SERVICE_CODE=*483*46#
|
||||
SUPPORT_PHONE_NUMBER=0757628885
|
||||
|
||||
[ussd]
|
||||
MENU_FILE=/usr/local/lib/python3.8/site-packages/cic_ussd/db/ussd_menu.json
|
||||
|
||||
@@ -41,3 +41,7 @@ def get_user_by_phone_number(phone_number: str) -> Optional[Account]:
|
||||
phone_number = process_phone_number(phone_number=phone_number, region='KE')
|
||||
user = Account.session.query(Account).filter_by(phone_number=phone_number).first()
|
||||
return user
|
||||
|
||||
|
||||
class Support:
|
||||
phone_number = None
|
||||
|
||||
@@ -19,7 +19,7 @@ from cic_ussd.db.models.ussd_session import UssdSession
|
||||
from cic_ussd.error import MetadataNotFoundError, SeppukuError
|
||||
from cic_ussd.menu.ussd_menu import UssdMenu
|
||||
from cic_ussd.metadata import blockchain_address_to_metadata_pointer
|
||||
from cic_ussd.phone_number import get_user_by_phone_number
|
||||
from cic_ussd.phone_number import get_user_by_phone_number, Support
|
||||
from cic_ussd.redis import cache_data, create_cached_data_key, get_cached_data
|
||||
from cic_ussd.state_machine import UssdStateMachine
|
||||
from cic_ussd.conversions import to_wei, from_wei
|
||||
@@ -270,7 +270,24 @@ def process_display_user_metadata(user: Account, display_key: str):
|
||||
products=products
|
||||
)
|
||||
else:
|
||||
raise MetadataNotFoundError(f'Expected person metadata but found none in cache for key: {key}')
|
||||
# TODO [Philip]: All these translations could be moved to translation files.
|
||||
logg.warning(f'Expected person metadata but found none in cache for key: {key}')
|
||||
|
||||
absent = ''
|
||||
if user.preferred_language == 'en':
|
||||
absent = 'Not provided'
|
||||
elif user.preferred_language == 'sw':
|
||||
absent = 'Haijawekwa'
|
||||
|
||||
return translation_for(
|
||||
key=display_key,
|
||||
preferred_language=user.preferred_language,
|
||||
full_name=absent,
|
||||
gender=absent,
|
||||
location=absent,
|
||||
products=absent
|
||||
)
|
||||
|
||||
|
||||
|
||||
def process_account_statement(user: Account, display_key: str, ussd_session: dict):
|
||||
@@ -406,12 +423,6 @@ def process_request(user_input: str, user: Account, ussd_session: Optional[dict]
|
||||
:return: A ussd menu's corresponding text value.
|
||||
:rtype: Document
|
||||
"""
|
||||
# retrieve metadata before any transition
|
||||
key = generate_metadata_pointer(
|
||||
identifier=blockchain_address_to_metadata_pointer(blockchain_address=user.blockchain_address),
|
||||
cic_type=':cic.person'
|
||||
)
|
||||
person_metadata = get_cached_data(key=key)
|
||||
|
||||
if ussd_session:
|
||||
if user_input == "0":
|
||||
@@ -435,7 +446,7 @@ def process_request(user_input: str, user: Account, ussd_session: Optional[dict]
|
||||
'exit_pin_mismatch',
|
||||
'exit_invalid_request',
|
||||
'exit_successful_transaction'
|
||||
] and person_metadata is not None:
|
||||
]:
|
||||
return UssdMenu.find_by_name(name='start')
|
||||
else:
|
||||
return UssdMenu.find_by_name(name=last_state)
|
||||
@@ -467,6 +478,14 @@ def next_state(ussd_session: dict, user: Account, user_input: str) -> str:
|
||||
return new_state
|
||||
|
||||
|
||||
def process_exit_invalid_menu_option(display_key: str, preferred_language: str):
|
||||
return translation_for(
|
||||
key=display_key,
|
||||
preferred_language=preferred_language,
|
||||
support_phone=Support.phone_number
|
||||
)
|
||||
|
||||
|
||||
def custom_display_text(
|
||||
display_key: str,
|
||||
menu_name: str,
|
||||
@@ -503,5 +522,7 @@ def custom_display_text(
|
||||
return process_account_statement(display_key=display_key, user=user, ussd_session=ussd_session)
|
||||
elif menu_name == 'display_user_metadata':
|
||||
return process_display_user_metadata(display_key=display_key, user=user)
|
||||
elif menu_name == 'exit_invalid_menu_option':
|
||||
return process_exit_invalid_menu_option(display_key=display_key, preferred_language=user.preferred_language)
|
||||
else:
|
||||
return translation_for(key=display_key, preferred_language=user.preferred_language)
|
||||
|
||||
@@ -26,7 +26,7 @@ from cic_ussd.metadata.base import Metadata
|
||||
from cic_ussd.operations import (define_response_with_content,
|
||||
process_menu_interaction_requests,
|
||||
define_multilingual_responses)
|
||||
from cic_ussd.phone_number import process_phone_number
|
||||
from cic_ussd.phone_number import process_phone_number, Support
|
||||
from cic_ussd.processor import get_default_token_data
|
||||
from cic_ussd.redis import cache_data, create_cached_data_key, InMemoryStore
|
||||
from cic_ussd.requests import (get_request_endpoint,
|
||||
@@ -126,6 +126,8 @@ else:
|
||||
|
||||
valid_service_codes = config.get('APP_SERVICE_CODE').split(",")
|
||||
|
||||
Support.phone_number = config.get('APP_SUPPORT_PHONE_NUMBER')
|
||||
|
||||
|
||||
def application(env, start_response):
|
||||
"""Loads python code for application to be accessible over web server
|
||||
@@ -143,7 +145,7 @@ def application(env, start_response):
|
||||
if get_request_method(env=env) == 'POST' and get_request_endpoint(env=env) == '/':
|
||||
|
||||
if env.get('CONTENT_TYPE') != 'application/x-www-form-urlencoded':
|
||||
start_response('405 Play by the rules', errors_headers)
|
||||
start_response('405 Urlencoded, please', errors_headers)
|
||||
return []
|
||||
|
||||
post_data = env.get('wsgi.input').read()
|
||||
@@ -211,6 +213,9 @@ def application(env, start_response):
|
||||
return [response_bytes]
|
||||
|
||||
else:
|
||||
logg.error('invalid query {}'.format(env))
|
||||
for r in env:
|
||||
logg.debug('{}: {}'.format(r, env))
|
||||
start_response('405 Play by the rules', errors_headers)
|
||||
return []
|
||||
|
||||
|
||||
@@ -11,7 +11,7 @@ from cic_ussd.balance import BalanceManager, compute_operational_balance
|
||||
from cic_ussd.chain import Chain
|
||||
from cic_ussd.db.models.account import AccountStatus, Account
|
||||
from cic_ussd.operations import save_to_in_memory_ussd_session_data
|
||||
from cic_ussd.phone_number import get_user_by_phone_number
|
||||
from cic_ussd.phone_number import get_user_by_phone_number, process_phone_number
|
||||
from cic_ussd.processor import retrieve_token_symbol
|
||||
from cic_ussd.redis import create_cached_data_key, get_cached_data
|
||||
from cic_ussd.transactions import OutgoingTransactionProcessor
|
||||
@@ -30,7 +30,7 @@ def is_valid_recipient(state_machine_data: Tuple[str, dict, Account]) -> bool:
|
||||
"""
|
||||
user_input, ussd_session, user = state_machine_data
|
||||
recipient = get_user_by_phone_number(phone_number=user_input)
|
||||
is_not_initiator = user_input != user.phone_number
|
||||
is_not_initiator = process_phone_number(user_input, 'KE') != user.phone_number
|
||||
has_active_account_status = user.get_account_status() == AccountStatus.ACTIVE.name
|
||||
return is_not_initiator and has_active_account_status and recipient is not None
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
cic_base[full_graph]~=0.1.2b14
|
||||
cic-eth~=0.11.0b15
|
||||
cic_base[full_graph]~=0.1.2b17
|
||||
cic-eth~=0.11.0b17
|
||||
cic-notify~=0.4.0a5
|
||||
cic-types~=0.1.0a10
|
||||
|
||||
@@ -36,26 +36,12 @@
|
||||
"source": "initial_pin_entry",
|
||||
"dest": "exit_invalid_pin"
|
||||
},
|
||||
{
|
||||
"trigger": "scan_data",
|
||||
"source": "initial_pin_confirmation",
|
||||
"dest": "start",
|
||||
"conditions": [
|
||||
"cic_ussd.state_machine.logic.pin.pins_match",
|
||||
"cic_ussd.state_machine.logic.validator.has_cached_user_metadata"
|
||||
],
|
||||
"after": [
|
||||
"cic_ussd.state_machine.logic.pin.complete_pin_change",
|
||||
"cic_ussd.state_machine.logic.user.get_user_metadata",
|
||||
"cic_ussd.state_machine.logic.user.update_account_status_to_active"
|
||||
]
|
||||
},
|
||||
{
|
||||
"trigger": "scan_data",
|
||||
"source": "initial_pin_confirmation",
|
||||
"unless": "cic_ussd.state_machine.logic.validator.has_cached_user_metadata",
|
||||
"conditions": "cic_ussd.state_machine.logic.pin.pins_match",
|
||||
"dest": "enter_given_name",
|
||||
"dest": "start",
|
||||
"after": [
|
||||
"cic_ussd.state_machine.logic.pin.complete_pin_change",
|
||||
"cic_ussd.state_machine.logic.user.update_account_status_to_active"
|
||||
|
||||
@@ -51,19 +51,13 @@ ENV PATH $NVM_DIR/versions/node//v$NODE_VERSION/bin:$PATH
|
||||
# WORKDIR /home/grassroots
|
||||
# USER grassroots
|
||||
|
||||
COPY contract-migration/requirements.txt .
|
||||
|
||||
ARG pip_extra_args=""
|
||||
ARG pip_index_url=https://pypi.org/simple
|
||||
ARG pip_extra_index_url=https://pip.grassrootseconomics.net:8433
|
||||
ARG cic_base_version=0.1.2b15
|
||||
ARG cic_eth_version=0.11.0b16
|
||||
ARG sarafu_token_version=0.0.1a8
|
||||
ARG sarafu_faucet_version=0.0.3a3
|
||||
RUN pip install --index-url https://pypi.org/simple --extra-index-url $pip_extra_index_url \
|
||||
cic-base[full_graph]==$cic_base_version \
|
||||
cic-eth==$cic_eth_version \
|
||||
sarafu-faucet==$sarafu_faucet_version \
|
||||
sarafu-token==$sarafu_token_version \
|
||||
cic-eth==$cic_eth_version
|
||||
RUN pip install --index-url https://pypi.org/simple \
|
||||
--extra-index-url $pip_extra_index_url -r requirements.txt
|
||||
|
||||
# -------------- begin runtime container ----------------
|
||||
FROM python:3.8.6-slim-buster as runtime-image
|
||||
|
||||
4
apps/contract-migration/requirements.txt
Normal file
4
apps/contract-migration/requirements.txt
Normal file
@@ -0,0 +1,4 @@
|
||||
cic-base[full_graph]==0.1.2b15
|
||||
sarafu-faucet==0.0.3a3
|
||||
sarafu-token==0.0.1a8
|
||||
cic-eth==0.11.0b16
|
||||
@@ -47,7 +47,7 @@ EOF
|
||||
|
||||
>&2 echo "create account for gas gifter"
|
||||
old_gas_provider=$DEV_ETH_ACCOUNT_GAS_PROVIDER
|
||||
DEV_ETH_ACCOUNT_GAS_GIFTER=`cic-eth-create $debug --redis-host-callback=$REDIS_HOST --redis-port-callback=$REDIS_PORT --no-register`
|
||||
DEV_ETH_ACCOUNT_GAS_GIFTER=`cic-eth-create --timeout 120 $debug --redis-host-callback=$REDIS_HOST --redis-port-callback=$REDIS_PORT --no-register`
|
||||
echo DEV_ETH_ACCOUNT_GAS_GIFTER=$DEV_ETH_ACCOUNT_GAS_GIFTER >> $env_out_file
|
||||
cic-eth-tag -i $CIC_CHAIN_SPEC GAS_GIFTER $DEV_ETH_ACCOUNT_GAS_GIFTER
|
||||
|
||||
|
||||
@@ -136,7 +136,7 @@ First, make a note of the **block height** before running anything:
|
||||
|
||||
To import, run to _completion_:
|
||||
|
||||
`python eth/import_users.py -v -c config -p <eth_provider> -r <cic_registry_address> -y ../keystore/UTC--2021-01-08T17-18-44.521011372Z--eb3907ecad74a0013c259d5874ae7f22dcbcc95c <datadir>`
|
||||
`python eth/import_users.py -v -c config -p <eth_provider> -r <cic_registry_address> -y ../contract-migration/keystore/UTC--2021-01-08T17-18-44.521011372Z--eb3907ecad74a0013c259d5874ae7f22dcbcc95c <datadir>`
|
||||
|
||||
After the script completes, keystore files for all generated accouts will be found in `<datadir>/keystore`, all with `foo` as password (would set it empty, but believe it or not some interfaces out there won't work unless you have one).
|
||||
|
||||
@@ -150,7 +150,7 @@ Then run:
|
||||
|
||||
Run in sequence, in first terminal:
|
||||
|
||||
`python cic_eth/import_balance.py -v -c config -p <eth_provider> -r <cic_registry_address> --token-symbol <token_symbol> -y ../keystore/UTC--2021-01-08T17-18-44.521011372Z--eb3907ecad74a0013c259d5874ae7f22dcbcc95c --head out`
|
||||
`python cic_eth/import_balance.py -v -c config -p <eth_provider> -r <cic_registry_address> --token-symbol <token_symbol> -y ../contract-migration/keystore/UTC--2021-01-08T17-18-44.521011372Z--eb3907ecad74a0013c259d5874ae7f22dcbcc95c --head out`
|
||||
|
||||
In another terminal:
|
||||
|
||||
@@ -226,7 +226,7 @@ The connection parameters for the `cic-ussd-server` is currently _hardcoded_ in
|
||||
|
||||
### Step 5 - Verify
|
||||
|
||||
`python verify.py -v -c config -r <cic_registry_address> -p <eth_provider> <datadir>`
|
||||
`python verify.py -v -c config -r <cic_registry_address> -p <eth_provider> --token-symbol <token_symbol> <datadir>`
|
||||
|
||||
Included checks:
|
||||
* Private key is in cic-eth keystore
|
||||
@@ -259,4 +259,8 @@ Should exit with code 0 if all input data is found in the respective services.
|
||||
|
||||
- Running the balance script should be _optional_ in all cases, but is currently required in the case of `cic_ussd` because it is needed to generate the metadata. An improvement would be moving the task to `import_users.py`, for a different queue than the balance tx handler.
|
||||
|
||||
- MacOS BigSur issue when installing psycopg2: ld: library not found for -lssl -> https://github.com/psycopg/psycopg2/issues/1115#issuecomment-831498953
|
||||
|
||||
- `cic_ussd` imports is poorly implemented, and consumes a lot of resources. Therefore it takes a long time to complete. Reducing the amount of polls for the phone pointer would go a long way to improve it.
|
||||
|
||||
- A strict constraint is maintained insistin the use of postgresql-12.
|
||||
|
||||
@@ -114,7 +114,7 @@ def main():
|
||||
conn = EthHTTPConnection(config.get('ETH_PROVIDER'))
|
||||
|
||||
ImportTask.balance_processor = BalanceProcessor(conn, chain_spec, config.get('CIC_REGISTRY_ADDRESS'), signer_address, signer)
|
||||
ImportTask.balance_processor.init()
|
||||
ImportTask.balance_processor.init(token_symbol)
|
||||
|
||||
# TODO get decimals from token
|
||||
balances = {}
|
||||
@@ -139,6 +139,7 @@ def main():
|
||||
|
||||
ImportTask.balances = balances
|
||||
ImportTask.count = i
|
||||
ImportTask.import_dir = user_dir
|
||||
|
||||
s = celery.signature(
|
||||
'import_task.send_txs',
|
||||
|
||||
@@ -39,6 +39,7 @@ elif args.vv:
|
||||
config_dir = args.c
|
||||
config = confini.Config(config_dir, os.environ.get('CONFINI_ENV_PREFIX'))
|
||||
config.process()
|
||||
logg.debug('config loaded from {}:\n{}'.format(args.c, config))
|
||||
|
||||
celery_app = celery.Celery(broker=config.get('CELERY_BROKER_URL'), backend=config.get('CELERY_RESULT_URL'))
|
||||
|
||||
@@ -62,9 +63,6 @@ def main():
|
||||
)
|
||||
s_import_pins.apply_async()
|
||||
|
||||
argv = ['worker', '-Q', 'cic-import-ussd', '--loglevel=DEBUG']
|
||||
celery_app.worker_main(argv)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
|
||||
@@ -1,29 +1,21 @@
|
||||
# standard imports
|
||||
import os
|
||||
import sys
|
||||
import argparse
|
||||
import json
|
||||
import logging
|
||||
import argparse
|
||||
import uuid
|
||||
import datetime
|
||||
import os
|
||||
import sys
|
||||
import time
|
||||
import urllib.request
|
||||
from glob import glob
|
||||
import uuid
|
||||
from urllib.parse import urlencode
|
||||
|
||||
# third-party imports
|
||||
import redis
|
||||
import confini
|
||||
# external imports
|
||||
import celery
|
||||
from hexathon import (
|
||||
add_0x,
|
||||
strip_0x,
|
||||
)
|
||||
from chainlib.eth.address import to_checksum
|
||||
from cic_types.models.person import Person
|
||||
from cic_eth.api.api_task import Api
|
||||
from chainlib.chain import ChainSpec
|
||||
from cic_types.processor import generate_metadata_pointer
|
||||
import confini
|
||||
import phonenumbers
|
||||
import redis
|
||||
from chainlib.chain import ChainSpec
|
||||
from cic_types.models.person import Person
|
||||
|
||||
logging.basicConfig(level=logging.WARNING)
|
||||
logg = logging.getLogger()
|
||||
@@ -87,21 +79,13 @@ chain_str = str(chain_spec)
|
||||
batch_size = args.batch_size
|
||||
batch_delay = args.batch_delay
|
||||
|
||||
db_configs = {
|
||||
'database': config.get('DATABASE_NAME'),
|
||||
'host': config.get('DATABASE_HOST'),
|
||||
'port': config.get('DATABASE_PORT'),
|
||||
'user': config.get('DATABASE_USER'),
|
||||
'password': config.get('DATABASE_PASSWORD')
|
||||
}
|
||||
|
||||
|
||||
def build_ussd_request(phone, host, port, service_code, username, password, ssl=False):
|
||||
url = 'http'
|
||||
if ssl:
|
||||
url += 's'
|
||||
url += '://{}:{}'.format(host, port)
|
||||
url += '/?username={}&password={}'.format(username, password) #config.get('USSD_USER'), config.get('USSD_PASS'))
|
||||
url += '/?username={}&password={}'.format(username, password)
|
||||
|
||||
logg.info('ussd service url {}'.format(url))
|
||||
logg.info('ussd phone {}'.format(phone))
|
||||
@@ -114,9 +98,10 @@ def build_ussd_request(phone, host, port, service_code, username, password, ssl=
|
||||
'text': service_code,
|
||||
}
|
||||
req = urllib.request.Request(url)
|
||||
data_str = json.dumps(data)
|
||||
req.method=('POST')
|
||||
data_str = urlencode(data)
|
||||
data_bytes = data_str.encode('utf-8')
|
||||
req.add_header('Content-Type', 'application/json')
|
||||
req.add_header('Content-Type', 'application/x-www-form-urlencoded')
|
||||
req.data = data_bytes
|
||||
|
||||
return req
|
||||
|
||||
@@ -31,9 +31,7 @@ elif args.vv:
|
||||
config_dir = args.c
|
||||
config = Config(config_dir, os.environ.get('CONFINI_ENV_PREFIX'))
|
||||
config.process()
|
||||
|
||||
user_old_dir = os.path.join(args.user_dir, 'old')
|
||||
os.stat(user_old_dir)
|
||||
logg.debug('config loaded from {}:\n{}'.format(args.c, config))
|
||||
|
||||
db_configs = {
|
||||
'database': config.get('DATABASE_NAME'),
|
||||
@@ -45,18 +43,15 @@ db_configs = {
|
||||
celery_app = celery.Celery(broker=config.get('CELERY_BROKER_URL'), backend=config.get('CELERY_RESULT_URL'))
|
||||
|
||||
if __name__ == '__main__':
|
||||
for x in os.walk(user_old_dir):
|
||||
for x in os.walk(args.user_dir):
|
||||
for y in x[2]:
|
||||
|
||||
if y[len(y) - 5:] != '.json':
|
||||
continue
|
||||
|
||||
# handle ussd_data json object
|
||||
if y[:15] == '_ussd_data.json':
|
||||
if y[len(y) - 5:] == '.json':
|
||||
filepath = os.path.join(x[0], y)
|
||||
f = open(filepath, 'r')
|
||||
try:
|
||||
ussd_data = json.load(f)
|
||||
logg.debug(f'LOADING USSD DATA: {ussd_data}')
|
||||
except json.decoder.JSONDecodeError as e:
|
||||
f.close()
|
||||
logg.error('load error for {}: {}'.format(y, e))
|
||||
|
||||
@@ -6,7 +6,7 @@ from eth_contract_registry import Registry
|
||||
from eth_token_index import TokenUniqueSymbolIndex
|
||||
from chainlib.eth.gas import OverrideGasOracle
|
||||
from chainlib.eth.nonce import OverrideNonceOracle
|
||||
from chainlib.eth.erc20 import ERC20
|
||||
from eth_erc20 import ERC20
|
||||
from chainlib.eth.tx import (
|
||||
count,
|
||||
TxFormat,
|
||||
@@ -37,7 +37,7 @@ class BalanceProcessor:
|
||||
self.value_multiplier = 1
|
||||
|
||||
|
||||
def init(self):
|
||||
def init(self, token_symbol):
|
||||
# Get Token registry address
|
||||
registry = Registry(self.chain_spec)
|
||||
o = registry.address_of(self.registry_address, 'TokenRegistry')
|
||||
@@ -46,10 +46,10 @@ class BalanceProcessor:
|
||||
logg.info('found token index address {}'.format(self.token_index_address))
|
||||
|
||||
token_registry = TokenUniqueSymbolIndex(self.chain_spec)
|
||||
o = token_registry.address_of(self.token_index_address, 'SRF')
|
||||
o = token_registry.address_of(self.token_index_address, token_symbol)
|
||||
r = self.conn.do(o)
|
||||
self.token_address = token_registry.parse_address_of(r)
|
||||
logg.info('found SRF token address {}'.format(self.token_address))
|
||||
logg.info('found {} token address {}'.format(token_symbol, self.token_address))
|
||||
|
||||
tx_factory = ERC20(self.chain_spec)
|
||||
o = tx_factory.decimals(self.token_address)
|
||||
|
||||
@@ -3,6 +3,7 @@ import argparse
|
||||
import json
|
||||
import logging
|
||||
import os
|
||||
import uuid
|
||||
|
||||
# third-party imports
|
||||
import bcrypt
|
||||
@@ -83,7 +84,7 @@ if __name__ == '__main__':
|
||||
|
||||
phone_object = phonenumbers.parse(u.tel)
|
||||
phone = phonenumbers.format_number(phone_object, phonenumbers.PhoneNumberFormat.E164)
|
||||
password_hash = generate_password_hash()
|
||||
password_hash = uuid.uuid4().hex
|
||||
pins_file.write(f'{phone},{password_hash}\n')
|
||||
logg.info(f'Writing phone: {phone}, password_hash: {password_hash}')
|
||||
|
||||
|
||||
@@ -9,6 +9,7 @@ import sys
|
||||
import urllib
|
||||
import urllib.request
|
||||
import uuid
|
||||
import urllib.parse
|
||||
|
||||
# external imports
|
||||
import celery
|
||||
@@ -72,7 +73,7 @@ argparser.add_argument('--ussd-provider', type=str, dest='ussd_provider', defaul
|
||||
argparser.add_argument('--skip-custodial', dest='skip_custodial', action='store_true', help='skip all custodial verifications')
|
||||
argparser.add_argument('--exclude', action='append', type=str, default=[], help='skip specified verification')
|
||||
argparser.add_argument('--include', action='append', type=str, help='include specified verification')
|
||||
argparser.add_argument('--token-symbol', default='SRF', type=str, dest='token_symbol', help='Token symbol to use for trnsactions')
|
||||
argparser.add_argument('--token-symbol', default='GFT', type=str, dest='token_symbol', help='Token symbol to use for trnsactions')
|
||||
argparser.add_argument('-r', '--registry-address', type=str, dest='r', help='CIC Registry address')
|
||||
argparser.add_argument('--env-prefix', default=os.environ.get('CONFINI_ENV_PREFIX'), dest='env_prefix', type=str, help='environment prefix for variables to overwrite configuration')
|
||||
argparser.add_argument('-x', '--exit-on-error', dest='x', action='store_true', help='Halt exection on error')
|
||||
@@ -185,9 +186,9 @@ def send_ussd_request(address, data_dir):
|
||||
}
|
||||
|
||||
req = urllib.request.Request(config.get('_USSD_PROVIDER'))
|
||||
data_str = json.dumps(data)
|
||||
data_bytes = data_str.encode('utf-8')
|
||||
req.add_header('Content-Type', 'application/json')
|
||||
urlencoded_data = urllib.parse.urlencode(data)
|
||||
data_bytes = urlencoded_data.encode('utf-8')
|
||||
req.add_header('Content-Type', 'application/x-www-form-urlencoded')
|
||||
req.data = data_bytes
|
||||
response = urllib.request.urlopen(req)
|
||||
return response.read().decode('utf-8')
|
||||
@@ -388,10 +389,9 @@ class Verifier:
|
||||
|
||||
def verify_ussd_pins(self, address, balance):
|
||||
response_data = send_ussd_request(address, self.data_dir)
|
||||
if response_data[:11] != 'CON Balance':
|
||||
if response_data[:11] != 'CON Balance' and response_data[:9] != 'CON Salio':
|
||||
raise VerifierError(response_data, 'pins')
|
||||
|
||||
|
||||
def verify(self, address, balance, debug_stem=None):
|
||||
|
||||
for k in active_tests:
|
||||
|
||||
Reference in New Issue
Block a user