diff --git a/property_tests/arbitraries/stable_b_tree_map_arb.ts b/property_tests/arbitraries/stable_b_tree_map_arb.ts index a5b4370659..32f37fea40 100644 --- a/property_tests/arbitraries/stable_b_tree_map_arb.ts +++ b/property_tests/arbitraries/stable_b_tree_map_arb.ts @@ -6,7 +6,9 @@ import { CandidValueAndMetaArb } from './candid/candid_value_and_meta_arb'; export const StableBTreeMapArb = fc .tuple( CandidValueAndMetaArb(), + argumentInfoArb(), CandidValueAndMetaArb(), + argumentInfoArb(), UniqueIdentifierArb('stableBTreeMap'), createUniquePrimitiveArb( fc.nat({ @@ -14,25 +16,66 @@ export const StableBTreeMapArb = fc }) ) ) - .map(([keySample, valueSample, uniqueIdentifier, memoryId]) => { - const name = `stableBTreeMap${uniqueIdentifier}`; - - const imports = new Set([ - ...keySample.src.imports, - ...valueSample.src.imports, - 'stableJson', - 'StableBTreeMap' - ]); - - return { - name, - imports, - definition: `let ${name} = StableBTreeMap<${keySample.src.candidTypeAnnotation}, ${valueSample.src.candidTypeAnnotation}>(${memoryId});`, + .map( + ([ keySample, - valueSample - }; - }); + keyArgumentInfo, + valueSample, + valueArgumentInfo, + uniqueIdentifier, + memoryId + ]) => { + const name = `stableBTreeMap${uniqueIdentifier}`; + + const imports = new Set([ + ...keySample.src.imports, + ...valueSample.src.imports, + 'stableJson', + 'StableBTreeMap' + ]); + + const serializableArguments = getSerializableArguments( + keySample, + valueSample, + keyArgumentInfo, + valueArgumentInfo + ); + + return { + name, + imports, + definition: `let ${name} = StableBTreeMap<${keySample.src.candidTypeAnnotation}, ${valueSample.src.candidTypeAnnotation}>(${memoryId}${serializableArguments});`, + keySample, + valueSample + }; + } + ); // TODO there must be a better way to get this type out, the sample will actually run export const StableBTreeMap = fc.sample(StableBTreeMapArb)[0]; export type StableBTreeMap = typeof StableBTreeMap; + +function getSerializableArguments( + keySample: StableBTreeMap['keySample'], + valueSample: StableBTreeMap['valueSample'], + keyArgumentInfo: 'STABLE_JSON' | 'CANDID_TYPE_OBJECT', + valueArgumentInfo: 'STABLE_JSON' | 'CANDID_TYPE_OBJECT' +): string { + const keyArgument = + keyArgumentInfo === 'STABLE_JSON' + ? 'stableJson' + : keySample.src.candidTypeObject; + const valueArgument = + valueArgumentInfo == 'STABLE_JSON' + ? 'stableJson' + : valueSample.src.candidTypeObject; + + return `, ${keyArgument}, ${valueArgument}`; +} + +function argumentInfoArb(): fc.Arbitrary<'STABLE_JSON' | 'CANDID_TYPE_OBJECT'> { + return fc.oneof( + fc.constant<'STABLE_JSON'>('STABLE_JSON'), + fc.constant<'CANDID_TYPE_OBJECT'>('CANDID_TYPE_OBJECT') + ); +} diff --git a/property_tests/tests/stable_b_tree_map/test/contains_key.ts b/property_tests/tests/stable_b_tree_map/test/contains_key.ts index 9168023c57..75e7f4ce6d 100644 --- a/property_tests/tests/stable_b_tree_map/test/contains_key.ts +++ b/property_tests/tests/stable_b_tree_map/test/contains_key.ts @@ -1,11 +1,11 @@ import fc from 'fast-check'; import { deepEqual } from 'fast-equals'; -import { getActor } from '../../../../property_tests'; -import { Test } from '../../../../test'; -import { UniqueIdentifierArb } from '../../../arbitraries/unique_identifier_arb'; -import { QueryMethod } from '../../../arbitraries/canister_methods/query_method_arb'; -import { StableBTreeMap } from '../../../arbitraries/stable_b_tree_map_arb'; +import { getActor } from 'azle/property_tests'; +import { Test } from 'azle/test'; +import { UniqueIdentifierArb } from 'azle/property_tests/arbitraries/unique_identifier_arb'; +import { QueryMethod } from 'azle/property_tests/arbitraries/canister_methods/query_method_arb'; +import { StableBTreeMap } from 'azle/property_tests/arbitraries/stable_b_tree_map_arb'; export function ContainsKeyTestArb(stableBTreeMap: StableBTreeMap) { return fc diff --git a/property_tests/tests/stable_b_tree_map/test/get.ts b/property_tests/tests/stable_b_tree_map/test/get.ts index 90382bd1fa..40af308781 100644 --- a/property_tests/tests/stable_b_tree_map/test/get.ts +++ b/property_tests/tests/stable_b_tree_map/test/get.ts @@ -1,11 +1,11 @@ import fc from 'fast-check'; import { deepEqual } from 'fast-equals'; -import { StableBTreeMap } from '../../../arbitraries/stable_b_tree_map_arb'; -import { getActor } from '../../../../property_tests'; -import { Test } from '../../../../test'; -import { UniqueIdentifierArb } from '../../../arbitraries/unique_identifier_arb'; -import { QueryMethod } from '../../../arbitraries/canister_methods/query_method_arb'; +import { StableBTreeMap } from 'azle/property_tests/arbitraries/stable_b_tree_map_arb'; +import { getActor } from 'azle/property_tests'; +import { Test } from 'azle/test'; +import { UniqueIdentifierArb } from 'azle/property_tests/arbitraries/unique_identifier_arb'; +import { QueryMethod } from 'azle/property_tests/arbitraries/canister_methods/query_method_arb'; export function GetTestArb(stableBTreeMap: StableBTreeMap) { return fc diff --git a/property_tests/tests/stable_b_tree_map/test/insert.ts b/property_tests/tests/stable_b_tree_map/test/insert.ts index 3d177ce589..bf5b4d259e 100644 --- a/property_tests/tests/stable_b_tree_map/test/insert.ts +++ b/property_tests/tests/stable_b_tree_map/test/insert.ts @@ -1,11 +1,11 @@ import fc from 'fast-check'; import { deepEqual } from 'fast-equals'; -import { StableBTreeMap } from '../../../arbitraries/stable_b_tree_map_arb'; -import { getActor } from '../../../../property_tests'; -import { Test } from '../../../../test'; -import { UniqueIdentifierArb } from '../../../arbitraries/unique_identifier_arb'; -import { QueryMethod } from '../../../arbitraries/canister_methods/query_method_arb'; +import { StableBTreeMap } from 'azle/property_tests/arbitraries/stable_b_tree_map_arb'; +import { getActor } from 'azle/property_tests'; +import { Test } from 'azle/test'; +import { UniqueIdentifierArb } from 'azle/property_tests/arbitraries/unique_identifier_arb'; +import { QueryMethod } from 'azle/property_tests/arbitraries/canister_methods/query_method_arb'; export function InsertTestArb(stableBTreeMap: StableBTreeMap) { return fc diff --git a/property_tests/tests/stable_b_tree_map/test/is_empty.ts b/property_tests/tests/stable_b_tree_map/test/is_empty.ts index 9e12c8d8e2..b6e2225b3f 100644 --- a/property_tests/tests/stable_b_tree_map/test/is_empty.ts +++ b/property_tests/tests/stable_b_tree_map/test/is_empty.ts @@ -1,11 +1,11 @@ import fc from 'fast-check'; import { deepEqual } from 'fast-equals'; -import { StableBTreeMap } from '../../../arbitraries/stable_b_tree_map_arb'; -import { getActor } from '../../../../property_tests'; -import { Test } from '../../../../test'; -import { UniqueIdentifierArb } from '../../../arbitraries/unique_identifier_arb'; -import { QueryMethod } from '../../../arbitraries/canister_methods/query_method_arb'; +import { StableBTreeMap } from 'azle/property_tests/arbitraries/stable_b_tree_map_arb'; +import { getActor } from 'azle/property_tests'; +import { Test } from 'azle/test'; +import { UniqueIdentifierArb } from 'azle/property_tests/arbitraries/unique_identifier_arb'; +import { QueryMethod } from 'azle/property_tests/arbitraries/canister_methods/query_method_arb'; export function IsEmptyTestArb(stableBTreeMap: StableBTreeMap) { return fc diff --git a/property_tests/tests/stable_b_tree_map/test/items.ts b/property_tests/tests/stable_b_tree_map/test/items.ts index 7b25890e69..d884550961 100644 --- a/property_tests/tests/stable_b_tree_map/test/items.ts +++ b/property_tests/tests/stable_b_tree_map/test/items.ts @@ -1,11 +1,11 @@ import fc from 'fast-check'; import { deepEqual } from 'fast-equals'; -import { StableBTreeMap } from '../../../arbitraries/stable_b_tree_map_arb'; -import { getActor } from '../../../../property_tests'; -import { Test } from '../../../../test'; -import { UniqueIdentifierArb } from '../../../arbitraries/unique_identifier_arb'; -import { QueryMethod } from '../../../arbitraries/canister_methods/query_method_arb'; +import { StableBTreeMap } from 'azle/property_tests/arbitraries/stable_b_tree_map_arb'; +import { getActor } from 'azle/property_tests'; +import { Test } from 'azle/test'; +import { UniqueIdentifierArb } from 'azle/property_tests/arbitraries/unique_identifier_arb'; +import { QueryMethod } from 'azle/property_tests/arbitraries/canister_methods/query_method_arb'; export function ItemsTestArb(stableBTreeMap: StableBTreeMap) { return fc diff --git a/property_tests/tests/stable_b_tree_map/test/keys.ts b/property_tests/tests/stable_b_tree_map/test/keys.ts index 7e288da31d..2250c43dfc 100644 --- a/property_tests/tests/stable_b_tree_map/test/keys.ts +++ b/property_tests/tests/stable_b_tree_map/test/keys.ts @@ -1,12 +1,12 @@ import fc from 'fast-check'; import { deepEqual } from 'fast-equals'; -import { StableBTreeMap } from '../../../arbitraries/stable_b_tree_map_arb'; -import { getActor } from '../../../../property_tests'; -import { Test } from '../../../../test'; +import { StableBTreeMap } from 'azle/property_tests/arbitraries/stable_b_tree_map_arb'; +import { getActor } from 'azle/property_tests'; +import { Test } from 'azle/test'; import { getArrayForCandidType, getArrayStringForCandidType } from './utils'; -import { UniqueIdentifierArb } from '../../../arbitraries/unique_identifier_arb'; -import { QueryMethod } from '../../../arbitraries/canister_methods/query_method_arb'; +import { UniqueIdentifierArb } from 'azle/property_tests/arbitraries/unique_identifier_arb'; +import { QueryMethod } from 'azle/property_tests/arbitraries/canister_methods/query_method_arb'; export function KeysTestArb(stableBTreeMap: StableBTreeMap) { return fc diff --git a/property_tests/tests/stable_b_tree_map/test/len.ts b/property_tests/tests/stable_b_tree_map/test/len.ts index 4522f1d3f0..7483221136 100644 --- a/property_tests/tests/stable_b_tree_map/test/len.ts +++ b/property_tests/tests/stable_b_tree_map/test/len.ts @@ -1,11 +1,11 @@ import fc from 'fast-check'; import { deepEqual } from 'fast-equals'; -import { StableBTreeMap } from '../../../arbitraries/stable_b_tree_map_arb'; -import { getActor } from '../../../../property_tests'; -import { Test } from '../../../../test'; -import { UniqueIdentifierArb } from '../../../arbitraries/unique_identifier_arb'; -import { QueryMethod } from '../../../arbitraries/canister_methods/query_method_arb'; +import { StableBTreeMap } from 'azle/property_tests/arbitraries/stable_b_tree_map_arb'; +import { getActor } from 'azle/property_tests'; +import { Test } from 'azle/test'; +import { UniqueIdentifierArb } from 'azle/property_tests/arbitraries/unique_identifier_arb'; +import { QueryMethod } from 'azle/property_tests/arbitraries/canister_methods/query_method_arb'; export function LenTestArb(stableBTreeMap: StableBTreeMap) { return fc diff --git a/property_tests/tests/stable_b_tree_map/test/remove.ts b/property_tests/tests/stable_b_tree_map/test/remove.ts index c12e394fdc..11f52531ad 100644 --- a/property_tests/tests/stable_b_tree_map/test/remove.ts +++ b/property_tests/tests/stable_b_tree_map/test/remove.ts @@ -1,11 +1,11 @@ import fc from 'fast-check'; import { deepEqual } from 'fast-equals'; -import { StableBTreeMap } from '../../../arbitraries/stable_b_tree_map_arb'; -import { getActor } from '../../../../property_tests'; -import { Test } from '../../../../test'; -import { UniqueIdentifierArb } from '../../../arbitraries/unique_identifier_arb'; -import { QueryMethod } from '../../../arbitraries/canister_methods/query_method_arb'; +import { StableBTreeMap } from 'azle/property_tests/arbitraries/stable_b_tree_map_arb'; +import { getActor } from 'azle/property_tests'; +import { Test } from 'azle/test'; +import { UniqueIdentifierArb } from 'azle/property_tests/arbitraries/unique_identifier_arb'; +import { QueryMethod } from 'azle/property_tests/arbitraries/canister_methods/query_method_arb'; export function RemoveTestArb(stableBTreeMap: StableBTreeMap) { return fc diff --git a/property_tests/tests/stable_b_tree_map/test/test.ts b/property_tests/tests/stable_b_tree_map/test/test.ts index 3e489601ca..97788dfc26 100644 --- a/property_tests/tests/stable_b_tree_map/test/test.ts +++ b/property_tests/tests/stable_b_tree_map/test/test.ts @@ -1,8 +1,8 @@ import fc from 'fast-check'; -import { runPropTests } from '../../../../property_tests'; -import { CanisterArb } from '../../../arbitraries/canister_arb'; -import { StableBTreeMapArb } from '../../../arbitraries/stable_b_tree_map_arb'; +import { runPropTests } from 'azle/property_tests'; +import { CanisterArb } from 'azle/property_tests/arbitraries/canister_arb'; +import { StableBTreeMapArb } from 'azle/property_tests/arbitraries/stable_b_tree_map_arb'; import { ContainsKeyTestArb } from './contains_key'; import { GetTestArb } from './get'; import { IsEmptyTestArb } from './is_empty'; @@ -42,11 +42,11 @@ const StableBTreeMapTestArb = fc ]) => { return { globalDeclarations: [ - stableBTreeMap.definition, ...stableBTreeMap.keySample.src .variableAliasDeclarations, ...stableBTreeMap.valueSample.src - .variableAliasDeclarations + .variableAliasDeclarations, + stableBTreeMap.definition ], queryMethods: [], updateMethods: [ @@ -65,7 +65,7 @@ const StableBTreeMapTestArb = fc ); }), { - minLength: 1, + minLength: 20, maxLength: 50 } ) diff --git a/property_tests/tests/stable_b_tree_map/test/values.ts b/property_tests/tests/stable_b_tree_map/test/values.ts index a635d9ad2a..18671c81b8 100644 --- a/property_tests/tests/stable_b_tree_map/test/values.ts +++ b/property_tests/tests/stable_b_tree_map/test/values.ts @@ -1,12 +1,12 @@ import fc from 'fast-check'; import { deepEqual } from 'fast-equals'; -import { StableBTreeMap } from '../../../arbitraries/stable_b_tree_map_arb'; -import { getActor } from '../../../../property_tests'; -import { Test } from '../../../../test'; +import { StableBTreeMap } from 'azle/property_tests/arbitraries/stable_b_tree_map_arb'; +import { getActor } from 'azle/property_tests'; +import { Test } from 'azle/test'; import { getArrayForCandidType, getArrayStringForCandidType } from './utils'; -import { UniqueIdentifierArb } from '../../../arbitraries/unique_identifier_arb'; -import { QueryMethod } from '../../../arbitraries/canister_methods/query_method_arb'; +import { UniqueIdentifierArb } from 'azle/property_tests/arbitraries/unique_identifier_arb'; +import { QueryMethod } from 'azle/property_tests/arbitraries/canister_methods/query_method_arb'; export function ValuesTestArb(stableBTreeMap: StableBTreeMap) { return fc