Skip to content

Commit

Permalink
Testnet with decentralized sequencer
Browse files Browse the repository at this point in the history
  • Loading branch information
szynwelski committed Dec 11, 2023
1 parent 5da88ff commit f6d1636
Show file tree
Hide file tree
Showing 9 changed files with 11 additions and 78 deletions.
11 changes: 2 additions & 9 deletions src/contract/HandlerBasedContract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -390,12 +390,7 @@ export class HandlerBasedContract<State> implements Contract<State> {
tags.push(new Tag(WARP_TAGS.REQUEST_VRF, 'true'));
}

const interactionTags = createInteractionTagsList(
this._contractTxId,
input,
this.warp.environment === 'testnet',
tags
);
const interactionTags = createInteractionTagsList(this._contractTxId, input, tags);

if (tagsExceedLimit(interactionTags)) {
throw new Error(`Interaction tags exceed limit of 4096 bytes.`);
Expand Down Expand Up @@ -452,7 +447,6 @@ export class HandlerBasedContract<State> implements Contract<State> {
transfer.target,
transfer.winstonQty,
bundle,
this.warp.environment === 'testnet',
reward
);

Expand Down Expand Up @@ -767,8 +761,7 @@ export class HandlerBasedContract<State> implements Contract<State> {
tags,
transfer.target,
transfer.winstonQty,
true,
this.warp.environment === 'testnet'
true
);
const dummyTx = createDummyTx(tx, executionContext.caller, currentBlockData);

Expand Down
2 changes: 0 additions & 2 deletions src/core/ContractDefinition.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ export class ContractCache<State> {
manifest?: EvaluationManifest;
contractTx: any; // eslint-disable-line @typescript-eslint/no-explicit-any
srcTx: any; // eslint-disable-line @typescript-eslint/no-explicit-any
testnet: string | null;

constructor(value: ContractDefinition<State>) {
this.txId = value.txId;
Expand All @@ -55,7 +54,6 @@ export class ContractCache<State> {
this.metadata = value.metadata;
this.contractTx = value.contractTx;
this.srcTx = value.srcTx;
this.testnet = value.testnet;
}
}

Expand Down
1 change: 0 additions & 1 deletion src/core/KnownTags.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ export const WARP_TAGS = {
REQUEST_VRF: 'Request-Vrf',
SIGNATURE_TYPE: 'Signature-Type',
UPLOADER_TX_ID: 'Uploader-Tx-Id',
WARP_TESTNET: 'Warp-Testnet',
MANIFEST: 'Contract-Manifest',
NONCE: 'Nonce'
} as const;
Expand Down
2 changes: 1 addition & 1 deletion src/core/Warp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ import { SourceData } from '../contract/deploy/Source';
import { Signer, DataItem } from 'warp-arbundles';
import { BasicSortKeyCache } from '../cache/BasicSortKeyCache';

export type WarpEnvironment = 'local' | 'testnet' | 'seqtestnet' | 'mainnet' | 'custom';
export type WarpEnvironment = 'local' | 'testnet' | 'mainnet' | 'custom';
export type KVStorageFactory = (contractTxId: string) => SortKeyCache<unknown>;

/**
Expand Down
26 changes: 3 additions & 23 deletions src/core/WarpFactory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,8 @@ export class WarpFactory {
}

/**
* creates a Warp instance suitable for testing
* with Warp testnet (https://testnet.redstone.tools/)
* creates a Warp instance suitable for testing with Warp testnet and the decentralized Warp Sequencer
* (https://github.com/warp-contracts/sequencer)
*/
static forTestnet(
cacheOptions = defaultCacheOptions,
Expand All @@ -83,27 +83,7 @@ export class WarpFactory {
if (useArweaveGw) {
return this.customArweaveGw(arweave, cacheOptions, 'testnet');
} else {
return this.customWarpGw(arweave, defaultWarpGwOptions, cacheOptions, 'testnet');
}
}

/**
* creates a Warp instance suitable for testing the decentralized Warp Sequencer
* (https://github.com/warp-contracts/sequencer)
*/
static forSeqTestnet(
cacheOptions = defaultCacheOptions,
useArweaveGw = false,
arweave = Arweave.init({
host: 'arweave.net',
port: 443,
protocol: 'https'
})
): Warp {
if (useArweaveGw) {
return this.customArweaveGw(arweave, cacheOptions, 'seqtestnet');
} else {
return this.customWarpGw(arweave, defaultWarpGwOptions, cacheOptions, 'seqtestnet').useGwUrl(WARP_GW_TESTNET_URL);
return this.customWarpGw(arweave, defaultWarpGwOptions, cacheOptions, 'testnet').useGwUrl(WARP_GW_TESTNET_URL);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,6 @@ export class ArweaveGatewayBundledContractDefinitionLoader implements Definition
const contractSrcTxId = evolvedSrcTxId
? evolvedSrcTxId
: getTagValue(contractTx.tags, SMART_WEAVE_TAGS.CONTRACT_SRC_TX_ID);
const testnet = getTagValue(contractTx.tags, WARP_TAGS.WARP_TESTNET) || null;

if (testnet && this.env !== 'testnet') {
throw new Error('Trying to use testnet contract in a non-testnet env. Use the "forTestnet" factory method.');
}
if (!testnet && this.env === 'testnet') {
throw new Error('Trying to use non-testnet contract in a testnet env.');
}

const minFee = getTagValue(contractTx.tags, SMART_WEAVE_TAGS.MIN_FEE);
const manifest = getTagValue(contractTx.tags, WARP_TAGS.MANIFEST)
Expand Down Expand Up @@ -77,8 +69,7 @@ export class ArweaveGatewayBundledContractDefinitionLoader implements Definition
metadata,
manifest,
contractTx: await this.convertToWarpCompatibleContractTx(contractTx),
srcTx: await this.convertToWarpCompatibleContractTx(srcTx),
testnet
srcTx: await this.convertToWarpCompatibleContractTx(srcTx)
};

this.logger.info(`Contract definition loaded in: ${benchmark.elapsed()}`);
Expand Down
10 changes: 1 addition & 9 deletions src/core/modules/impl/ContractDefinitionLoader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,6 @@ export class ContractDefinitionLoader implements DefinitionLoader {
const contractSrcTxId = forcedSrcTxId
? forcedSrcTxId
: this.tagsParser.getTag(contractTx, SMART_WEAVE_TAGS.CONTRACT_SRC_TX_ID);
const testnet = this.tagsParser.getTag(contractTx, WARP_TAGS.WARP_TESTNET) || null;
if (testnet && this.env !== 'testnet') {
throw new Error('Trying to use testnet contract in a non-testnet env. Use the "forTestnet" factory method.');
}
if (!testnet && this.env === 'testnet') {
throw new Error('Trying to use non-testnet contract in a testnet env.');
}
const minFee = this.tagsParser.getTag(contractTx, SMART_WEAVE_TAGS.MIN_FEE);
let manifest = null;
const rawManifest = this.tagsParser.getTag(contractTx, WARP_TAGS.MANIFEST);
Expand Down Expand Up @@ -86,8 +79,7 @@ export class ContractDefinitionLoader implements DefinitionLoader {
metadata,
manifest,
contractTx: contractTx.toJSON(),
srcTx,
testnet
srcTx
};
}

Expand Down
11 changes: 0 additions & 11 deletions src/core/modules/impl/WarpGatewayContractDefinitionLoader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,11 @@ export class WarpGatewayContractDefinitionLoader implements DefinitionLoader {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
result.srcBinary = Buffer.from((result.srcBinary as any).data);
}
this.verifyEnv(result);
return result;
}
const benchmark = Benchmark.measure();
const contract = await this.doLoad<State>(contractTxId, evolvedSrcTxId);
this.rLogger.info(`Contract definition loaded in: ${benchmark.elapsed()}`);
this.verifyEnv(contract);

await this.putToCache(contractTxId, contract, evolvedSrcTxId);

Expand Down Expand Up @@ -119,15 +117,6 @@ export class WarpGatewayContractDefinitionLoader implements DefinitionLoader {
return this.srcCache;
}

private verifyEnv(def: ContractDefinition<unknown>): void {
if (def.testnet && this.env !== 'testnet') {
throw new Error('Trying to use testnet contract in a non-testnet env. Use the "forTestnet" factory method.');
}
if (!def.testnet && this.env === 'testnet') {
throw new Error('Trying to use non-testnet contract in a testnet env.');
}
}

// Gets ContractDefinition and ContractSource from two caches and returns a combined structure
private async getFromCache<State>(contractTxId: string, srcTxId?: string): Promise<ContractDefinition<State> | null> {
const contract = (await this.definitionCache.get(new CacheKey(contractTxId, 'cd'))) as SortKeyCacheResult<
Expand Down
15 changes: 3 additions & 12 deletions src/legacy/create-interaction-tx.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import Arweave from 'arweave';
import { SMART_WEAVE_TAGS, WARP_TAGS } from '../core/KnownTags';
import { SMART_WEAVE_TAGS } from '../core/KnownTags';
import { GQLNodeInterface } from './gqlResult';
import { TagsParser } from '../core/modules/impl/TagsParser';
import { SigningFunction } from '../contract/Signature';
Expand All @@ -15,7 +15,6 @@ export async function createInteractionTx<Input>(
target = '',
winstonQty = '0',
dummy = false,
isTestnet: boolean,
reward?: string
): Promise<Transaction> {
const options: Partial<CreateTransactionInterface> = {
Expand Down Expand Up @@ -43,7 +42,7 @@ export async function createInteractionTx<Input>(

const interactionTx = await arweave.createTransaction(options);

const interactionTags = createInteractionTagsList(contractId, input, isTestnet, tags);
const interactionTags = createInteractionTagsList(contractId, input, tags);
interactionTags.forEach((t) => interactionTx.addTag(t.name, t.value));

if (signer) {
Expand Down Expand Up @@ -100,12 +99,7 @@ export function createDummyTx(tx: Transaction, from: string, block: BlockData):
};
}

export function createInteractionTagsList<Input>(
contractId: string,
input: Input,
isTestnet: boolean,
customTags?: Tags
) {
export function createInteractionTagsList<Input>(contractId: string, input: Input, customTags?: Tags) {
const interactionTags: Tags = [];

if (customTags && customTags.length) {
Expand All @@ -120,9 +114,6 @@ export function createInteractionTagsList<Input>(
interactionTags.push(new Tag(SMART_WEAVE_TAGS.SDK, 'Warp'));
interactionTags.push(new Tag(SMART_WEAVE_TAGS.CONTRACT_TX_ID, contractId));
interactionTags.push(new Tag(SMART_WEAVE_TAGS.INPUT, JSON.stringify(input)));
if (isTestnet) {
interactionTags.push(new Tag(WARP_TAGS.WARP_TESTNET, '1.0.0'));
}

return interactionTags;
}

0 comments on commit f6d1636

Please sign in to comment.