Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tests running correctly #225

Merged
merged 1 commit into from
Aug 25, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 3 additions & 5 deletions packages/core/src/implementations/business/QueryService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -166,9 +166,7 @@ export class QueryService implements IQueryService {
| QueryFormatError
| EvaluationError
> {
console.log(
`Processing query for consent contract ${consentContractAddress} with CID ${query.cid}`,
);
//console.log(`Processing query for consent contract ${consentContractAddress} with CID ${query.cid}`,);
return ResultUtils.combine([
this.contextProvider.getContext(),
this.configProvider.getConfig(),
Expand All @@ -188,7 +186,7 @@ export class QueryService implements IQueryService {
const maps2 = maps as [InsightString[], EligibleReward[]];
const insights = maps2[0];
const rewards = maps2[1];
console.log("insights: ", insights);
//console.log("insights: ", insights);
// console.log("rewards: ", rewards);

// console.log(insights, rewards);
Expand All @@ -200,7 +198,7 @@ export class QueryService implements IQueryService {
query.cid,
insights,
).map(() => {
console.log("insight delivery api call done");
// console.log("insight delivery api call done");
// context.publicEvents.onQueryPosted.next({
// consentContractAddress,
// query,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ export class BalanceQueryEvaluator implements IBalanceQueryEvaluator {
balance: BigNumber.from("0"),
};
})
console.log("TokenBalances: ", tokenBalances)
return okAsync(tokenBalances);
}
).andThen( (balanceArray) => {
Expand All @@ -70,32 +69,31 @@ export class BalanceQueryEvaluator implements IBalanceQueryEvaluator {
//console.log("Condition: ", condition);
//console.log("balanceArray: ", balanceArray);
let val: BigNumber = BigNumber.from(0);
console.log("Val: ", val.toNumber());
switch (condition.constructor) {
case ConditionGE:
val = BigNumber.from((condition as ConditionGE).rval);
console.log("val: ", val.toNumber());
//console.log("val: ", val.toNumber());
balanceArray = balanceArray.filter((balance) => BigNumber.from((balance.balance)).toNumber() >= val.toNumber());
console.log("BalanceArray: ", balanceArray);
//console.log("BalanceArray: ", balanceArray);
break;
case ConditionG:
val = BigNumber.from((condition as ConditionG).rval);
console.log("val: ", val.toNumber());
//console.log("val: ", val.toNumber());
balanceArray = balanceArray.filter((balance) => BigNumber.from((balance.balance)).toNumber() > val.toNumber());
break;
case ConditionL:
val = BigNumber.from((condition as ConditionL).rval);
console.log("val: ", val.toNumber());
//console.log("val: ", val.toNumber());
balanceArray = balanceArray.filter((balance) => BigNumber.from((balance.balance)).toNumber() < val.toNumber());
break;
case ConditionE:
val = BigNumber.from((condition as ConditionE).rval);
console.log("val: ", val.toNumber());
//console.log("val: ", val.toNumber());
balanceArray = balanceArray.filter((balance) => BigNumber.from((balance.balance)).toNumber() == val.toNumber());
break;
case ConditionLE:
val = BigNumber.from((condition as ConditionLE).rval);
console.log("val: ", val.toNumber());
//console.log("val: ", val.toNumber());
balanceArray = balanceArray.filter((balance) => BigNumber.from((balance.balance)).toNumber() <= val.toNumber());
break;

Expand Down
2 changes: 1 addition & 1 deletion packages/core/test/unit/business/QueryService.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ describe("processQuery tests", () => {
await queryService
.processQuery(consentContractAddress, sdqlQuery)
.andThen((result) => {
console.log("result", result);
//console.log("result", result);
expect(result).toBeUndefined();
// expect(result.isOk()).toBeTruthy();
return okAsync(true);
Expand Down
12 changes: 9 additions & 3 deletions packages/core/test/unit/business/query/AST_Evaluator.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@ import {
ConditionL,
ConditionOr,
} from "@core/interfaces/objects";
import { IQueryFactories } from "@core/interfaces/utilities/factory";
import { IQueryFactories, IQueryObjectFactory } from "@core/interfaces/utilities/factory";
import { IBalanceQueryEvaluator } from "@core/interfaces/business/utilities/query/IBalanceQueryEvaluator";
import { BalanceQueryEvaluator } from "@core/implementations/business/utilities/query/BalanceQueryEvaluator";

// const ast = new AST(
// Version("0.1"),
Expand All @@ -39,20 +41,24 @@ import { IQueryFactories } from "@core/interfaces/utilities/factory";

class ASTMocks {
public persistenceRepo = td.object<IDataWalletPersistence>();
public queryObjectFactory = td.object<IQueryObjectFactory>();

public queryFactories: IQueryFactories;
// protected queryRepository = td.object<IQueryRepository>();
public queryRepository: QueryRepository;
public queryEvaluator: QueryEvaluator;
public balanceQueryEvaluator: IBalanceQueryEvaluator;

public constructor() {
this.queryFactories = new QueryFactories();
this.queryFactories = new QueryFactories(this.queryObjectFactory);
this.balanceQueryEvaluator = new BalanceQueryEvaluator(this.persistenceRepo);

td.when(this.persistenceRepo.getAge()).thenReturn(okAsync(Age(25)));
td.when(this.persistenceRepo.getLocation()).thenReturn(
okAsync(CountryCode("1")),
);

this.queryEvaluator = new QueryEvaluator(this.persistenceRepo);
this.queryEvaluator = new QueryEvaluator(this.persistenceRepo, this.balanceQueryEvaluator);
this.queryRepository = new QueryRepository(this.queryEvaluator);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ describe("BalanceQueryEvaluator", () => {
const balanceQuery = new AST_BalanceQuery(
SDQL_Name("q7"),
"array",
"*",
null, // * - for all, use null
[],
)
// >= 20 and < 30
Expand Down
12 changes: 9 additions & 3 deletions packages/core/test/unit/business/query/ExprParser.test.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import "reflect-metadata";

import { IpfsCID } from "@objects/primitives";
import { IpfsCID, SDQLString } from "@objects/primitives";

import { avalance1SchemaStr } from "./avalanche1.data";

import {
ExprParser,
QueryObjectFactory,
SDQLParser,
Token,
Tokenizer,
Expand All @@ -22,6 +23,9 @@ import {
ConditionOr,
SDQLSchema,
} from "@core/interfaces/objects/SDQL";
import { IQueryObjectFactory } from "@core/interfaces/utilities/factory";
import td from "testdouble";

// import { ExprParser } from "businessObjects/SDQL/ExprParser";
// import { Token, Tokenizer, TokenType } from "businessObjects/SDQL/Tokenizer";
// import { IpfsCID } from "primitives";
Expand Down Expand Up @@ -339,8 +343,10 @@ describe("Postfix expressions", () => {
});

describe("Postfix to AST", () => {
const schema = SDQLSchema.fromString(avalance1SchemaStr);
const parser = new SDQLParser(IpfsCID("0"), schema);
const schema = SDQLSchema.fromString(SDQLString(avalance1SchemaStr));
let queryObjectFactory = td.object<IQueryObjectFactory>();

const parser = new SDQLParser(IpfsCID("0"), schema, queryObjectFactory);
parser.buildAST();
const context = parser.context;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -904,7 +904,7 @@ describe("Return Chain Transaction Count", () => {
})
})


/*
describe("BalanceQueryEvaluator", () => {
test("Return Query Balance Array - 1 Chain ID, 20 <= x < 30", async () => {
const balanceQuery = new AST_BalanceQuery(
Expand Down Expand Up @@ -955,3 +955,4 @@ describe("BalanceQueryEvaluator", () => {
expect(result["value"].length).toEqual(4)
})
})
*/