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

Added for ride v6 compilation tests #35

Open
wants to merge 25 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
a989aba
refactoring constant names, add match test's for ride_v6
Jun 15, 2022
aab2f82
added new function tests sqrtIntAndUnion, sqrtBigIntAndUnion
Jun 15, 2022
95c17ac
added new tests STDLIB_VERSION_6, for rsaVerify.test.ts and sigVerify…
Jun 15, 2022
0b3d5fa
added new tests STDLIB_VERSION_6, for groth16Verify.test.ts
Jun 15, 2022
6199744
added new tests STDLIB_VERSION_6, for ecrecover.test.ts
Jun 15, 2022
161a11c
added new tests STDLIB_VERSION_6, for createMerkleRoot.test.ts
Jun 15, 2022
fc35bc2
added new tests STDLIB_VERSION_6, for bn256Groth16Verify.test.ts
Jun 15, 2022
5212793
added new tests STDLIB_VERSION_6, for functions converting
Jun 16, 2022
a4e2788
added test's for ride V6
Jun 16, 2022
8ac3ab9
added test's for ride V6. hashing functions
Jun 16, 2022
94247b0
added test's for ride V6. accountDataStorage functions
Jun 16, 2022
a2a0894
added test's for ride V6. blockchain functions
Jun 16, 2022
e4457b6
added test's for ride V6. dappToDappInvocation, dataTransaction,
Jun 17, 2022
0225123
added construction with argument before function. getBinary tests
Jun 20, 2022
16f6d67
added construction with argument before function.
Jun 20, 2022
3e4b541
added construction with argument before function.
Jun 20, 2022
123c8a6
added tests sqrt BigInt
Jun 20, 2022
ffb7c39
added functions tests, with arguments before function
Jun 21, 2022
4ad7d30
added functions tests, with arguments before function
Jun 23, 2022
2e8dbae
code style edited
Jun 23, 2022
629b178
added data transaction functions tests, with arguments before function
Jun 23, 2022
84cc614
added string functions tests, with arguments before function
Jun 23, 2022
d3a6ff7
added hashing, list, union functions tests, with arguments before fun…
Jun 24, 2022
b22700c
added bn256Groth16Verify, groth16Verify, rsaVerify, sigVerify
Jun 24, 2022
e42e73e
small edited getBinary.test.ts
Jun 27, 2022
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
28 changes: 16 additions & 12 deletions test/builtInFunctions/GenerateContractForBuiltInFunctions.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

export class GenerateContractForBuiltInFunctions {

private readonly defaultFunction;
Expand All @@ -12,7 +11,7 @@ export class GenerateContractForBuiltInFunctions {
}

public generateContractFromMatchingAndCase
(libVersion, caseForVersions, testData, getFunction = this.defaultFunction):string {
(libVersion, caseForVersions, testData, getFunction = this.defaultFunction): string {
return `
{-# STDLIB_VERSION ${libVersion} #-}
{-# CONTENT_TYPE DAPP #-}
Expand All @@ -22,15 +21,16 @@ export class GenerateContractForBuiltInFunctions {
func expression() = {
let callerTestData = ${testData}
let valueOrUnit = ${getFunction}
let throwMessage = "not ${this.dataType}"
let val = match(valueOrUnit) {
case b:${this.dataType} => b
case _ => throw("not ${this.dataType}")
case _ => throwMessage.throw()
}
${caseForVersions}
}`;
};

public generateContractOwnData(libVersion, caseForVersions, ownDataFunction = this.ownDataFunction):string {
public generateContractOwnData(libVersion, caseForVersions, ownDataFunction = this.ownDataFunction): string {
return `
{-# STDLIB_VERSION ${libVersion} #-}
{-# CONTENT_TYPE DAPP #-}
Expand All @@ -48,7 +48,7 @@ export class GenerateContractForBuiltInFunctions {
};

public generateContractWithoutMatcher
(libVersion, caseForVersions, testData, getFunction = this.defaultFunction):string {
(libVersion, caseForVersions, testData, getFunction = this.defaultFunction): string {
return `
{-# STDLIB_VERSION ${libVersion} #-}
{-# CONTENT_TYPE DAPP #-}
Expand All @@ -63,7 +63,7 @@ export class GenerateContractForBuiltInFunctions {
};

public generateContractOwnDataWithoutMatcher
(libVersion, caseForVersions, ownDataFunction = this.ownDataFunction):string {
(libVersion, caseForVersions, ownDataFunction = this.ownDataFunction): string {
return `
{-# STDLIB_VERSION ${libVersion} #-}
{-# CONTENT_TYPE DAPP #-}
Expand All @@ -76,8 +76,8 @@ export class GenerateContractForBuiltInFunctions {
}`;
};

public generateOnlyMatcherContract(libVersion, testData, getFunction = this.defaultFunction):string {
return `
public generateOnlyMatcherContract(libVersion, testData, getFunction = this.defaultFunction): string {
const result = (`
{-# STDLIB_VERSION ${libVersion} #-}
{-# CONTENT_TYPE DAPP #-}
{-# SCRIPT_TYPE ACCOUNT #-}
Expand All @@ -86,10 +86,12 @@ export class GenerateContractForBuiltInFunctions {
let x = match ${getFunction} {
case h:${this.dataType} => h
case _ => throw("not ${this.dataType}")
}`
}`);

return result;
}

public generateContract(version, foo, bar, testFunction):string {
public generateContract(version, foo, bar, testFunction): string {
return `
{-# STDLIB_VERSION ${version} #-}
{-# CONTENT_TYPE DAPP #-}
Expand All @@ -101,14 +103,16 @@ export class GenerateContractForBuiltInFunctions {
}

public generateContractForDAppInvocation
(libVersion, byteVector, payment, getFunctionName = this.defaultFunction):string {
(libVersion, byteVector, payment, func = this.defaultFunction): string {
return `
{-# STDLIB_VERSION ${libVersion} #-}
{-# CONTENT_TYPE DAPP #-}
{-# SCRIPT_TYPE ACCOUNT #-}

func foo(dapp2: String, a: Int, key1: String, key2: String) = {
strict res = ${getFunctionName}(addressFromStringValue(dapp2),"bar",[a],[AttachedPayment(${byteVector}, ${payment})])
let byteVector = ${byteVector}
let payment = ${payment}
strict res = ${func}
match res {
case r : Int =>
(
Expand Down
126 changes: 85 additions & 41 deletions test/builtInFunctions/accountDataStorage/getBinary.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,71 +3,115 @@ import * as random from "../../testData/random";

import {GenerateContractForBuiltInFunctions} from "../GenerateContractForBuiltInFunctions";
import {checkCompileResult} from "../testResult";
import {getRandomString} from "../../testData/random";

describe('getBinary', () => {
describe('getBinary', () => {
// getBinary
const getBinary = `getBinary(callerTestData, ${getRandomString()})`;
const getBinaryArgBeforeFunc = `callerTestData.getBinary(${getRandomString()})`;
const ownDataGetBinary = `getBinary(${getRandomString()})`;
const ownDataGetBinaryArgBeforeFunc = `${getRandomString()}.getBinary()`;

const getBinary = `getBinary(callerTestData, "Ȣ瞱蛉㦎᠖꭛믳癚曉续")`;
const invalidGetBinaryV3 = `getBinary(callerTestData)`;
const invalidGetBinaryGreaterV3 = `getBinary(callerTestData)`;
const ownDataGetBinary = 'getBinary("LJKaSADfHH127gd")';
// getBinaryValue
const getBinaryValue = `getBinaryValue(callerTestData, ${getRandomString()})`;
const getBinaryValueArgBeforeFunc = `callerTestData.getBinaryValue(${getRandomString()})`;
const ownDataGetBinaryValue = `getBinaryValue(${getRandomString()})`;
const ownDataGetBinaryValueArgBeforeFunc = `${getRandomString()}.getBinaryValue()`;

const getBinaryValue = `getBinaryValue(callerTestData, "LJKaSADfHH782gd")`
const invalidGetBinaryValueV3 = `getBinaryValue(callerTestData)`;
const invalidGetBinaryValueGreaterV3 = `getBinaryValue(callerTestData)`;
const ownDataGetBinaryValue = 'getBinaryValue("LJKaSADfHH127gd")';
const invalidGetBinary = `getBinary(callerTestData)`;
const invalidGetBinaryValue = `getBinaryValue(callerTestData)`;

const precondition = new GenerateContractForBuiltInFunctions
(getBinary, ownDataGetBinary, 'ByteVector');

test.each([
// getBinary
[data.STDLIB_VERSION_3, getBinary, data.RideV3Result, random.getRandomAddress(), data.positiveTestType],
[data.STDLIB_VERSION_4, getBinary, data.GreaterV3ResultBinaryEntry, random.getRandomAddress(), data.positiveTestType],
[data.STDLIB_VERSION_5, getBinary, data.GreaterV3ResultBinaryEntry, random.getRandomAddress(), data.positiveTestType],
[data.STDLIB_VERSION_3, getBinary, data.RideV3Result, random.getRandomAlias(), data.positiveTestType],
[data.STDLIB_VERSION_4, getBinary, data.GreaterV3ResultBinaryEntry, random.getRandomAlias(), data.positiveTestType],
[data.STDLIB_VERSION_5, getBinary, data.GreaterV3ResultBinaryEntry, random.getRandomAlias(), data.positiveTestType],
// getBinaryValue
[data.STDLIB_VERSION_3, getBinaryValue, data.RideV3Result, random.getRandomAddress(), data.positiveTestType],
[data.STDLIB_VERSION_4, getBinaryValue, data.GreaterV3ResultBinaryEntry, random.getRandomAddress(), data.positiveTestType],
[data.STDLIB_VERSION_5, getBinaryValue, data.GreaterV3ResultBinaryEntry, random.getRandomAddress(), data.positiveTestType],
[data.STDLIB_VERSION_3, getBinaryValue, data.RideV3Result, random.getRandomAlias(), data.positiveTestType],
[data.STDLIB_VERSION_4, getBinaryValue, data.GreaterV3ResultBinaryEntry, random.getRandomAlias(), data.positiveTestType],
[data.STDLIB_VERSION_5, getBinaryValue, data.GreaterV3ResultBinaryEntry, random.getRandomAlias(), data.positiveTestType],
// getBinary address
[data.STDLIB_VERSION_3, getBinary, data.RideV3Result, random.getRandomAddress(), data.POSITIVE_TEST],
[data.STDLIB_VERSION_4, getBinary, data.GreaterV3ResultBinaryEntry, random.getRandomAddress(), data.POSITIVE_TEST],
[data.STDLIB_VERSION_5, getBinary, data.GreaterV3ResultBinaryEntry, random.getRandomAddress(), data.POSITIVE_TEST],
[data.STDLIB_VERSION_6, getBinary, data.GreaterV3ResultBinaryEntry, random.getRandomAddress(), data.POSITIVE_TEST],
// getBinary alias
[data.STDLIB_VERSION_3, getBinary, data.RideV3Result, random.getRandomAlias(), data.POSITIVE_TEST],
[data.STDLIB_VERSION_4, getBinary, data.GreaterV3ResultBinaryEntry, random.getRandomAlias(), data.POSITIVE_TEST],
[data.STDLIB_VERSION_5, getBinary, data.GreaterV3ResultBinaryEntry, random.getRandomAlias(), data.POSITIVE_TEST],
[data.STDLIB_VERSION_6, getBinary, data.GreaterV3ResultBinaryEntry, random.getRandomAlias(), data.POSITIVE_TEST],

// getBinary address arg before func
[data.STDLIB_VERSION_3, getBinaryArgBeforeFunc, data.RideV3Result, random.getRandomAddress(), data.POSITIVE_TEST],
[data.STDLIB_VERSION_4, getBinaryArgBeforeFunc, data.GreaterV3ResultBinaryEntry, random.getRandomAddress(), data.POSITIVE_TEST],
[data.STDLIB_VERSION_5, getBinaryArgBeforeFunc, data.GreaterV3ResultBinaryEntry, random.getRandomAddress(), data.POSITIVE_TEST],
[data.STDLIB_VERSION_6, getBinaryArgBeforeFunc, data.GreaterV3ResultBinaryEntry, random.getRandomAddress(), data.POSITIVE_TEST],
// getBinary alias arg before func
[data.STDLIB_VERSION_3, getBinaryArgBeforeFunc, data.RideV3Result, random.getRandomAlias(), data.POSITIVE_TEST],
[data.STDLIB_VERSION_4, getBinaryArgBeforeFunc, data.GreaterV3ResultBinaryEntry, random.getRandomAlias(), data.POSITIVE_TEST],
[data.STDLIB_VERSION_5, getBinaryArgBeforeFunc, data.GreaterV3ResultBinaryEntry, random.getRandomAlias(), data.POSITIVE_TEST],
[data.STDLIB_VERSION_6, getBinaryArgBeforeFunc, data.GreaterV3ResultBinaryEntry, random.getRandomAlias(), data.POSITIVE_TEST],

// getBinaryValue address
[data.STDLIB_VERSION_3, getBinaryValue, data.RideV3Result, random.getRandomAddress(), data.POSITIVE_TEST],
[data.STDLIB_VERSION_4, getBinaryValue, data.GreaterV3ResultBinaryEntry, random.getRandomAddress(), data.POSITIVE_TEST],
[data.STDLIB_VERSION_5, getBinaryValue, data.GreaterV3ResultBinaryEntry, random.getRandomAddress(), data.POSITIVE_TEST],
[data.STDLIB_VERSION_6, getBinaryValue, data.GreaterV3ResultBinaryEntry, random.getRandomAddress(), data.POSITIVE_TEST],
// getBinaryValue alias
[data.STDLIB_VERSION_3, getBinaryValue, data.RideV3Result, random.getRandomAlias(), data.POSITIVE_TEST],
[data.STDLIB_VERSION_4, getBinaryValue, data.GreaterV3ResultBinaryEntry, random.getRandomAlias(), data.POSITIVE_TEST],
[data.STDLIB_VERSION_5, getBinaryValue, data.GreaterV3ResultBinaryEntry, random.getRandomAlias(), data.POSITIVE_TEST],
[data.STDLIB_VERSION_6, getBinaryValue, data.GreaterV3ResultBinaryEntry, random.getRandomAlias(), data.POSITIVE_TEST],

// getBinaryValue address arg before func
[data.STDLIB_VERSION_3, getBinaryValueArgBeforeFunc, data.RideV3Result, random.getRandomAddress(), data.POSITIVE_TEST],
[data.STDLIB_VERSION_4, getBinaryValueArgBeforeFunc, data.GreaterV3ResultBinaryEntry, random.getRandomAddress(), data.POSITIVE_TEST],
[data.STDLIB_VERSION_5, getBinaryValueArgBeforeFunc, data.GreaterV3ResultBinaryEntry, random.getRandomAddress(), data.POSITIVE_TEST],
[data.STDLIB_VERSION_6, getBinaryValueArgBeforeFunc, data.GreaterV3ResultBinaryEntry, random.getRandomAddress(), data.POSITIVE_TEST],
// getBinaryValue alias arg before func
[data.STDLIB_VERSION_3, getBinaryValueArgBeforeFunc, data.RideV3Result, random.getRandomAlias(), data.POSITIVE_TEST],
[data.STDLIB_VERSION_4, getBinaryValueArgBeforeFunc, data.GreaterV3ResultBinaryEntry, random.getRandomAlias(), data.POSITIVE_TEST],
[data.STDLIB_VERSION_5, getBinaryValueArgBeforeFunc, data.GreaterV3ResultBinaryEntry, random.getRandomAlias(), data.POSITIVE_TEST],
[data.STDLIB_VERSION_6, getBinaryValueArgBeforeFunc, data.GreaterV3ResultBinaryEntry, random.getRandomAlias(), data.POSITIVE_TEST],

// negative: invalid function getBinary
[data.STDLIB_VERSION_3, invalidGetBinaryV3, data.RideV3Result, random.getRandomAddress(), data.negativeTestType],
[data.STDLIB_VERSION_3, invalidGetBinaryV3, data.GreaterV3ResultBinaryEntry, random.getRandomAlias(), data.negativeTestType],
[data.STDLIB_VERSION_4, invalidGetBinaryGreaterV3, data.GreaterV3ResultBinaryEntry, random.getRandomAddress(), data.negativeTestType],
[data.STDLIB_VERSION_5, invalidGetBinaryGreaterV3, data.GreaterV3ResultBinaryEntry, random.getRandomAlias(), data.negativeTestType],
[data.STDLIB_VERSION_3, invalidGetBinary, data.RideV3Result, random.getRandomAddress(), data.NEGATIVE_TEST],
[data.STDLIB_VERSION_4, invalidGetBinary, data.GreaterV3ResultBinaryEntry, random.getRandomAddress(), data.NEGATIVE_TEST],
[data.STDLIB_VERSION_5, invalidGetBinary, data.GreaterV3ResultBinaryEntry, random.getRandomAlias(), data.NEGATIVE_TEST],
[data.STDLIB_VERSION_6, invalidGetBinary, data.GreaterV3ResultBinaryEntry, random.getRandomAddress(), data.NEGATIVE_TEST],

// negative: invalid function getBinaryValue
[data.STDLIB_VERSION_3, invalidGetBinaryValueV3, data.RideV3Result, random.getRandomAddress(), data.negativeTestType],
[data.STDLIB_VERSION_3, invalidGetBinaryValueV3, data.GreaterV3ResultBinaryEntry, random.getRandomAlias(), data.negativeTestType],
[data.STDLIB_VERSION_4, invalidGetBinaryValueGreaterV3, data.GreaterV3ResultBinaryEntry, random.getRandomAddress(), data.negativeTestType],
[data.STDLIB_VERSION_5, invalidGetBinaryValueGreaterV3, data.GreaterV3ResultBinaryEntry, random.getRandomAlias(), data.negativeTestType],
[data.STDLIB_VERSION_3, invalidGetBinaryValue, data.RideV3Result, random.getRandomAddress(), data.NEGATIVE_TEST],
[data.STDLIB_VERSION_4, invalidGetBinaryValue, data.GreaterV3ResultBinaryEntry, random.getRandomAddress(), data.NEGATIVE_TEST],
[data.STDLIB_VERSION_5, invalidGetBinaryValue, data.GreaterV3ResultBinaryEntry, random.getRandomAlias(), data.NEGATIVE_TEST],
[data.STDLIB_VERSION_6, invalidGetBinaryValue, data.GreaterV3ResultBinaryEntry, random.getRandomAlias(), data.NEGATIVE_TEST],
])('check ride v%i function %s compiles or failed', (version, testFunction, scriptResult, testString, testType) => {
const contract = precondition.generateContractFromMatchingAndCase(version, scriptResult, testString, testFunction);
checkCompileResult(contract, testType);
});

test.each([
[data.STDLIB_VERSION_5, data.GreaterV3ResultBinaryEntry, data.positiveTestType],
[data.STDLIB_VERSION_5, data.GreaterV3ResultBinaryEntry, ownDataGetBinary, data.POSITIVE_TEST],
[data.STDLIB_VERSION_5, data.GreaterV3ResultBinaryEntry, ownDataGetBinaryArgBeforeFunc, data.POSITIVE_TEST],
[data.STDLIB_VERSION_6, data.GreaterV3ResultBinaryEntry, ownDataGetBinary, data.POSITIVE_TEST],
[data.STDLIB_VERSION_6, data.GreaterV3ResultBinaryEntry, ownDataGetBinaryArgBeforeFunc, data.POSITIVE_TEST],
// Can't find a function overload getBinary
[data.STDLIB_VERSION_3, data.RideV3Result, data.negativeTestType],
[data.STDLIB_VERSION_4, data.GreaterV3ResultBinaryEntry, data.negativeTestType],
])('getBinary own data tests', (version, scriptResult, testType) => {
const contract = precondition.generateContractOwnData(version, scriptResult);
[data.STDLIB_VERSION_3, data.RideV3Result, ownDataGetBinary, data.NEGATIVE_TEST],
[data.STDLIB_VERSION_3, data.RideV3Result, ownDataGetBinaryArgBeforeFunc, data.NEGATIVE_TEST],
[data.STDLIB_VERSION_4, data.GreaterV3ResultBinaryEntry, ownDataGetBinary, data.NEGATIVE_TEST],
[data.STDLIB_VERSION_4, data.GreaterV3ResultBinaryEntry, ownDataGetBinaryArgBeforeFunc, data.NEGATIVE_TEST],
])('getBinary own data tests', (version, scriptResult, func, testType) => {
const contract = precondition.generateContractOwnData(version, scriptResult, func);
checkCompileResult(contract, testType);
});

test.each([
[data.STDLIB_VERSION_5, data.GreaterV3ResultBinaryEntry, data.positiveTestType,],
[data.STDLIB_VERSION_5, data.GreaterV3ResultBinaryEntry, ownDataGetBinaryValue, data.POSITIVE_TEST],
[data.STDLIB_VERSION_5, data.GreaterV3ResultBinaryEntry, ownDataGetBinaryValue, data.POSITIVE_TEST],
[data.STDLIB_VERSION_6, data.GreaterV3ResultBinaryEntry, ownDataGetBinaryValueArgBeforeFunc, data.POSITIVE_TEST],
[data.STDLIB_VERSION_6, data.GreaterV3ResultBinaryEntry, ownDataGetBinaryValueArgBeforeFunc, data.POSITIVE_TEST],
// Can't find a function overload getBinaryValue
[data.STDLIB_VERSION_3, data.RideV3Result, data.negativeTestType],
[data.STDLIB_VERSION_4, data.GreaterV3ResultBinaryEntry, data.negativeTestType],
])('getBinaryValue own data tests', (version, scriptResult, testType) => {
const contract = precondition.generateContractOwnDataWithoutMatcher(version, scriptResult, ownDataGetBinaryValue);
[data.STDLIB_VERSION_3, data.RideV3Result, ownDataGetBinaryValue, data.NEGATIVE_TEST],
[data.STDLIB_VERSION_3, data.RideV3Result, ownDataGetBinaryValueArgBeforeFunc, data.NEGATIVE_TEST],
[data.STDLIB_VERSION_4, data.GreaterV3ResultBinaryEntry, ownDataGetBinaryValue, data.NEGATIVE_TEST],
[data.STDLIB_VERSION_4, data.GreaterV3ResultBinaryEntry, ownDataGetBinaryValueArgBeforeFunc, data.NEGATIVE_TEST],
])('getBinaryValue own data tests', (version, scriptResult, func, testType) => {
const contract = precondition.generateContractOwnDataWithoutMatcher(version, scriptResult, func);
checkCompileResult(contract, testType);
});
});
Loading