Skip to content

Commit

Permalink
refactor!: drop Iris support
Browse files Browse the repository at this point in the history
BREAKING CHANGE: Iris is not supported
Stick to a previous sdk version if it is required.
  • Loading branch information
davidyuk committed Jun 8, 2024
1 parent 905d6ae commit 61554b3
Show file tree
Hide file tree
Showing 11 changed files with 40 additions and 57 deletions.
9 changes: 2 additions & 7 deletions src/aens.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
import BigNumber from 'bignumber.js';
import { genSalt, isAddressValid } from './utils/crypto';
import { commitmentHash, isAuctionName } from './tx/builder/helpers';
import { Tag, AensName, ConsensusProtocolVersion } from './tx/builder/constants';
import { Tag, AensName } from './tx/builder/constants';
import { Encoded, Encoding } from './utils/encoder';
import { UnsupportedProtocolError, LogicError } from './utils/errors';
import { LogicError } from './utils/errors';
import { getName } from './chain';
import { sendTransaction, SendTransactionOptions } from './send-transaction';
import { Optional } from './utils/other';
Expand Down Expand Up @@ -125,11 +125,6 @@ export default class Name {

const hasRawPointers = Object.values(allPointers)
.some((v) => isAddressValid(v, Encoding.Bytearray));
const isIris = (await opt.onNode.getNodeInfo())
.consensusProtocolVersion === ConsensusProtocolVersion.Iris;
if (hasRawPointers && isIris) {
throw new UnsupportedProtocolError('Raw pointers are available only in Ceres, the current protocol is Iris');
}

const tx = await buildTxAsync({
_isInternalBuild: true,
Expand Down
8 changes: 2 additions & 6 deletions src/contract/Contract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@
*/

import { Encoder as Calldata } from '@aeternity/aepp-calldata';
import {
Tag, AensName, ConsensusProtocolVersion, DRY_RUN_ACCOUNT,
} from '../tx/builder/constants';
import { Tag, AensName, DRY_RUN_ACCOUNT } from '../tx/builder/constants';
import {
buildContractIdByContractTx, unpackTx, buildTxAsync, BuildTxOptions, buildTxHash,
} from '../tx/builder';
Expand Down Expand Up @@ -501,9 +499,7 @@ class Contract<M extends ContractMethodsBase> {
'contract_pubkey',
{ resolveByNode: true, onNode },
) as Encoded.ContractAddress;
const isIris = (await onNode.getNodeInfo())
.consensusProtocolVersion === ConsensusProtocolVersion.Iris;
if (!isIris && isNameValid(address)) name = address;
if (isNameValid(address)) name = address;
}

if (address == null && sourceCode == null && sourceCodePath == null && bytecode == null) {
Expand Down
1 change: 0 additions & 1 deletion src/tx/builder/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ export const NAME_BID_RANGES = mapObject({
}, ([key, value]) => [key, new BigNumber(value).times(NAME_FEE_MULTIPLIER)]);

export enum ConsensusProtocolVersion {
Iris = 5,
Ceres = 6,
}

Expand Down
2 changes: 1 addition & 1 deletion src/tx/builder/field-types/abi-version.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export default {
serialize(
value: AbiVersion | undefined,
{ tag }: { tag: Tag },
{ consensusProtocolVersion = ConsensusProtocolVersion.Iris }:
{ consensusProtocolVersion = ConsensusProtocolVersion.Ceres }:
{ consensusProtocolVersion?: ConsensusProtocolVersion },
): Buffer {
const result = value ?? this._getProtocolDetails(consensusProtocolVersion, tag);
Expand Down
13 changes: 1 addition & 12 deletions src/tx/builder/field-types/ct-version.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,6 @@ import Node from '../../../Node';
* @see {@link https://github.com/aeternity/protocol/blob/71cf111/contracts/contract_vms.md#virtual-machines-on-the-æternity-blockchain}
*/
export const ProtocolToVmAbi = {
[ConsensusProtocolVersion.Iris]: {
'contract-create': {
vmVersion: [VmVersion.Fate2], abiVersion: [AbiVersion.Fate],
},
'contract-call': {
vmVersion: [], abiVersion: [AbiVersion.Fate, AbiVersion.Sophia],
},
'oracle-call': {
vmVersion: [], abiVersion: [AbiVersion.NoAbi, AbiVersion.Fate],
},
},
[ConsensusProtocolVersion.Ceres]: {
'contract-create': {
vmVersion: [VmVersion.Fate3], abiVersion: [AbiVersion.Fate],
Expand Down Expand Up @@ -50,7 +39,7 @@ export default {
serialize(
value: CtVersion | undefined,
params: {},
{ consensusProtocolVersion = ConsensusProtocolVersion.Iris }:
{ consensusProtocolVersion = ConsensusProtocolVersion.Ceres }:
{ consensusProtocolVersion?: ConsensusProtocolVersion },
): Buffer {
value ??= getProtocolDetails(consensusProtocolVersion, 'contract-create');
Expand Down
10 changes: 9 additions & 1 deletion src/tx/builder/field-types/nonce.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@ import shortUInt from './short-u-int';
import Node from '../../../Node';
import { ArgumentError } from '../../../utils/errors';
import { NextNonceStrategy } from '../../../apis/node';
import { Tag } from '../constants';

export default function genNonceField<SenderKey extends string>(senderKey: SenderKey): {
serialize: (value: number) => Buffer;
serialize: (value: number, params: { tag: Tag }) => Buffer;
// TODO: (value: number) => Promise<number> | (value: undefined, ...) => Promise<number>
prepare: (
value: number | undefined,
Expand All @@ -23,6 +24,13 @@ export default function genNonceField<SenderKey extends string>(senderKey: Sende
return {
...shortUInt,

serialize(value: number, { tag }): Buffer {
if (Tag.GaAttachTx === tag && value !== 1) {
throw new ArgumentError('nonce', 'equal 1 if GaAttachTx', value);
}
return shortUInt.serialize(value);
},

async prepare(value, params, options) {
if (value != null) return value;
// TODO: uncomment the below line
Expand Down
11 changes: 0 additions & 11 deletions src/tx/validator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -208,15 +208,4 @@ validators.push(
}];
}
},
// TODO: move to fee field of tx builder after dropping Iris
(tx, { consensusProtocolVersion }) => ((
Tag.GaAttachTx === tx.tag
&& ConsensusProtocolVersion.Ceres === consensusProtocolVersion
&& tx.nonce !== 1
) ? [{
message: `Account ${tx.ownerId} can't become generalized because it is already used`,
key: 'AccountUsed',
checkedKeys: ['nonce'],
}]
: []),
);
18 changes: 18 additions & 0 deletions test/integration/account-generalized.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
Contract, ContractMethodsBase,
MIN_GAS_PRICE,
Encoded,
ArgumentError,
} from '../../src';
import { ensureEqual } from '../utils';

Expand Down Expand Up @@ -61,6 +62,23 @@ describe('Generalized Account', () => {
.should.be.rejectedWith(`Account ${gaAccountAddress} is already GA`);
});

it('fails to build GaAttachTx with non-1 nonce', () => {
expect(() => buildTx({
tag: Tag.GaAttachTx,
version: 1,
ownerId: 'ak_Yd9EiaBy8GNXWLkMuH53H9hiCyEuL3RKxN4wYKhN8xDnjKRpb',
nonce: 2,
code: 'cb_+LJGA6BFoqzc6YC/ewZLk3eumqCWL/K7O2Wqy+x14Zbcx4rB0MC4hbhV/kTWRB8ANwA3ABoOgq+CAAEAPwEDP/5s8lcLADcBBxd3AoJ3AAg8AgT7A01Ob3QgaW4gQXV0aCBjb250ZXh0AQP//qsVVmEANwCHAjcANwGXQAECgqovAxFE1kQfEWluaXQRbPJXCyVhdXRob3JpemURqxVWYSVnZXRUeEhhc2iCLwCFOC4wLjAAdzf5cQ==',
authFun: Buffer.from('6cf2570b0a1599b708291e50aa3daf13d0c7f2484bc337ddad2413a37fd4a009', 'hex'),
ctVersion: { vmVersion: 8, abiVersion: 3 },
fee: '80620000000000',
ttl: 0,
gasLimit: 107,
gasPrice: '1000000000',
callData: 'cb_KxFE1kQfP4oEp9E=',
})).to.throw(ArgumentError, 'nonce should be equal 1 if GaAttachTx, got 2 instead');
});

const { publicKey } = generateKeyPair();

it('Init MemoryAccount for GA and Spend using GA', async () => {
Expand Down
2 changes: 1 addition & 1 deletion test/integration/chain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,6 @@ describe('Node Chain', () => {
.foo(v, { nonce: nextNonce + idx, gasLimit, combine: true })),
)).map((r) => r.decodedResult);
expect(results).to.be.eql(numbers.map((v) => BigInt(v * 100)));
expect(getCount()).to.be.equal(2);
expect(getCount()).to.be.equal(1);
});
});
13 changes: 6 additions & 7 deletions test/integration/node.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { describe, it, before } from 'mocha';
import { expect } from 'chai';
import { createSandbox } from 'sinon';
import { stub } from 'sinon';
import { RestError } from '@azure/core-rest-pipeline';
import { FullOperationResponse } from '@azure/core-client';
import { url } from '.';
import {
AeSdkBase, Node, NodeNotFoundError, ConsensusProtocolVersion, MemoryAccount, buildTx, Tag,
AeSdkBase, Node, NodeNotFoundError, MemoryAccount, buildTx, Tag,
} from '../../src';
import { bindRequestCounter } from '../utils';

Expand Down Expand Up @@ -67,12 +67,11 @@ describe('Node client', () => {
}, Promise.resolve()));

it('throws exception if unsupported protocol', async () => {
const sandbox = createSandbox();
sandbox.stub(ConsensusProtocolVersion, 'Ceres' as any).value(undefined);
sandbox.stub(ConsensusProtocolVersion, '6' as any).value(undefined);
const status = await node.getStatus();
const s = stub(node, 'getStatus').resolves({ ...status, topBlockHeight: 0 });
await expect(node.getNodeInfo()).to.be
.rejectedWith('Unsupported consensus protocol version 6. Supported: >= 5 < 6');
sandbox.restore();
.rejectedWith('Unsupported consensus protocol version 1. Supported: >= 6 < 7');
s.restore();
});

it('throws exception with code', async () => {
Expand Down
10 changes: 0 additions & 10 deletions test/integration/txVerification.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,14 +93,4 @@ describe('Verify Transaction', () => {
const errors = await verifyTransaction(contractCall, node);
expect(errors.map(({ key }) => key)).to.include('ContractNotFound');
});

it('verifies nonce of gaAttach transaction', async () => {
const gaAttach = 'tx_+QEWUAGhAUfN4Ejc4KynKrM1XI1D2AWlqBrTeCVywu9B6hV4rnriAri0+LJGA6BFoqzc6YC/ewZLk3eumqCWL/K7O2Wqy+x14Zbcx4rB0MC4hbhV/kTWRB8ANwA3ABoOgq+CAAEAPwEDP/5s8lcLADcBBxd3AoJ3AAg8AgT7A01Ob3QgaW4gQXV0aCBjb250ZXh0AQP//qsVVmEANwCHAjcANwGXQAECgqovAxFE1kQfEWluaXQRbPJXCyVhdXRob3JpemURqxVWYSVnZXRUeEhhc2iCLwCFOC4wLjAAoGzyVwsKFZm3CCkeUKo9rxPQx/JIS8M33a0kE6N/1KAJgwgAA4ZJUs52OAAAa4Q7msoAhysRRNZEHz/z50Zp';
const errors = await verifyTransaction(gaAttach, node);
expect(errors.find((e) => e.key === 'AccountUsed')).to.eql({
message: 'Account ak_Yd9EiaBy8GNXWLkMuH53H9hiCyEuL3RKxN4wYKhN8xDnjKRpb can\'t become generalized because it is already used',
key: 'AccountUsed',
checkedKeys: ['nonce'],
});
});
});

0 comments on commit 61554b3

Please sign in to comment.