Skip to content

Commit

Permalink
test(contract): restore Iris compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
davidyuk committed Jan 31, 2024
1 parent e5ee64e commit 33616db
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
16 changes: 13 additions & 3 deletions test/integration/contract-aci.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import {
AE_AMOUNT_FORMATS,
Tag,
NoSuchContractFunctionError,
ConsensusProtocolVersion,
} from '../../src';
import { getSdk } from '.';
import {
Expand All @@ -36,7 +37,7 @@ namespace TestLib =
function sum(x: int, y: int) = x + y
`;

const testContractSourceCode = `
const getTestContractSourceCode = (isIris: boolean): string => `
namespace Test =
function double(x: int) = x * 2
Expand Down Expand Up @@ -86,7 +87,7 @@ contract StateContract =
entrypoint hashFn(s: hash) = s
entrypoint signatureFn(s: signature) = s
entrypoint bytesFn(s: bytes(32)) = s
entrypoint bytesAnySizeFn(s: bytes) = s
${isIris ? '' : 'entrypoint bytesAnySizeFn(s: bytes) = s'}
entrypoint bitsFn(s: bits) = s
Expand All @@ -101,7 +102,7 @@ contract StateContract =
entrypoint chainTtlFn(t: Chain.ttl) = t
entrypoint aensV2Name(name: AENSv2.name) = name
${isIris ? '' : 'entrypoint aensV2Name(name: AENSv2.name) = name'}
stateful entrypoint recursion(t: string) =
put(state{value = t})
Expand Down Expand Up @@ -185,13 +186,18 @@ interface TestContractApi extends ContractMethodsBase {

describe('Contract instance', () => {
let aeSdk: AeSdk;
let isIris: boolean;
let testContractSourceCode: string;
let testContract: Contract<TestContractApi>;
let testContractAddress: Encoded.ContractAddress;
let testContractAci: Aci;
let testContractBytecode: Encoded.ContractBytearray;

before(async () => {
aeSdk = await getSdk(2);
isIris = (await aeSdk.api.getNodeInfo())
.consensusProtocolVersion === ConsensusProtocolVersion.Iris;
testContractSourceCode = getTestContractSourceCode(isIris);
const res = await aeSdk.compilerApi.compileBySourceCode(testContractSourceCode, fileSystem);
testContractAci = res.aci;
testContractBytecode = res.bytecode;
Expand Down Expand Up @@ -1060,11 +1066,13 @@ describe('Contract instance', () => {

describe('Bytes any size', () => {
it('Invalid type', async () => {
if (isIris) return;
await expect(testContract.bytesAnySizeFn({} as any))
.to.be.rejectedWith('Should be one of: Array, ArrayBuffer, hex string, Number, BigInt; got [object Object] instead');
});

it('Valid', async () => {
if (isIris) return;
const decoded = Buffer.from('0xdeadbeef', 'hex');
const { decodedResult: hashAsBuffer } = await testContract.bytesAnySizeFn(decoded);
const { decodedResult: hashAsHex } = await testContract.bytesAnySizeFn(decoded.toString('hex'));
Expand Down Expand Up @@ -1100,11 +1108,13 @@ describe('Contract instance', () => {

describe('AENSv2.name', () => {
it('Invalid', async () => {
if (isIris) return;
await expect(testContract.aensV2Name({ 'AENSv2.Name': ['test'] } as any))
.to.be.rejectedWith('"AENSv2.Name" variant constructor expects 3 argument(s) but got 1 instead');
});

it('Valid', async () => {
if (isIris) return;
const value: AENSv2Name = {
'AENSv2.Name': [
'ak_nRqnePWC6yGWBmR4wfN3AvQnqbv2TizxKJdvGXj8p7YZrUZ5J',
Expand Down
1 change: 1 addition & 0 deletions test/integration/delegation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,7 @@ contract DelegateTest =
});

it('claims without preclaim', async () => {
if (isIris) return;
const n = randomName(15);
const nameFee = 20e18;
const dlgSig = await aeSdk.createDelegationSignature(contractAddress, [n]);
Expand Down

0 comments on commit 33616db

Please sign in to comment.