fix: [BUG] unsafeClient evaluationOptions vs manifest #425
This commit is contained in:
2
.github/workflows/tests.yml
vendored
2
.github/workflows/tests.yml
vendored
@@ -13,6 +13,8 @@ jobs:
|
|||||||
version: 'latest'
|
version: 'latest'
|
||||||
- name: Install modules
|
- name: Install modules
|
||||||
run: yarn
|
run: yarn
|
||||||
|
- name: Lint
|
||||||
|
run: yarn lint
|
||||||
- name: Build package
|
- name: Build package
|
||||||
run: yarn build
|
run: yarn build
|
||||||
- name: Run unit tests
|
- name: Run unit tests
|
||||||
|
|||||||
@@ -102,13 +102,115 @@ describe('Evaluation options evaluator', () => {
|
|||||||
walletBalanceUrl: 'http://nyc-1.dev.arweave.net:1984/'
|
walletBalanceUrl: 'http://nyc-1.dev.arweave.net:1984/'
|
||||||
});
|
});
|
||||||
|
|
||||||
expect(function () {
|
expect(new EvaluationOptionsEvaluator(contract2.evaluationOptions(), {
|
||||||
const result = new EvaluationOptionsEvaluator(contract2.evaluationOptions(), {
|
|
||||||
internalWrites: false
|
internalWrites: false
|
||||||
|
}).rootOptions).toEqual({
|
||||||
|
allowBigInt: false,
|
||||||
|
cacheEveryNInteractions: -1,
|
||||||
|
gasLimit: 2222,
|
||||||
|
ignoreExceptions: true,
|
||||||
|
internalWrites: false,
|
||||||
|
maxCallDepth: 5,
|
||||||
|
maxInteractionEvaluationTimeSeconds: 60,
|
||||||
|
mineArLocalBlocks: true,
|
||||||
|
remoteStateSyncEnabled: false,
|
||||||
|
remoteStateSyncSource: 'https://dre-1.warp.cc/contract',
|
||||||
|
sequencerUrl: 'https://d1o5nlqr4okus2.cloudfront.net/',
|
||||||
|
sourceType: 'both',
|
||||||
|
stackTrace: {
|
||||||
|
saveState: false
|
||||||
|
},
|
||||||
|
throwOnInternalWriteError: true,
|
||||||
|
unsafeClient: 'allow',
|
||||||
|
updateCacheForEachInteraction: false,
|
||||||
|
useKVStorage: false,
|
||||||
|
waitForConfirmation: false,
|
||||||
|
useConstructor: false,
|
||||||
|
walletBalanceUrl: 'http://nyc-1.dev.arweave.net:1984/'
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(new EvaluationOptionsEvaluator(contract2.evaluationOptions(), {
|
||||||
|
unsafeClient: 'throw'
|
||||||
|
}).rootOptions).toEqual({
|
||||||
|
allowBigInt: false,
|
||||||
|
cacheEveryNInteractions: -1,
|
||||||
|
gasLimit: 2222,
|
||||||
|
ignoreExceptions: true,
|
||||||
|
internalWrites: true,
|
||||||
|
maxCallDepth: 5,
|
||||||
|
maxInteractionEvaluationTimeSeconds: 60,
|
||||||
|
mineArLocalBlocks: true,
|
||||||
|
remoteStateSyncEnabled: false,
|
||||||
|
remoteStateSyncSource: 'https://dre-1.warp.cc/contract',
|
||||||
|
sequencerUrl: 'https://d1o5nlqr4okus2.cloudfront.net/',
|
||||||
|
sourceType: 'both',
|
||||||
|
stackTrace: {
|
||||||
|
saveState: false
|
||||||
|
},
|
||||||
|
throwOnInternalWriteError: true,
|
||||||
|
unsafeClient: 'throw',
|
||||||
|
updateCacheForEachInteraction: false,
|
||||||
|
useKVStorage: false,
|
||||||
|
waitForConfirmation: false,
|
||||||
|
useConstructor: false,
|
||||||
|
walletBalanceUrl: 'http://nyc-1.dev.arweave.net:1984/'
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(new EvaluationOptionsEvaluator(contract2.evaluationOptions(), {
|
||||||
|
unsafeClient: 'skip'
|
||||||
|
}).rootOptions).toEqual({
|
||||||
|
allowBigInt: false,
|
||||||
|
cacheEveryNInteractions: -1,
|
||||||
|
gasLimit: 2222,
|
||||||
|
ignoreExceptions: true,
|
||||||
|
internalWrites: true,
|
||||||
|
maxCallDepth: 5,
|
||||||
|
maxInteractionEvaluationTimeSeconds: 60,
|
||||||
|
mineArLocalBlocks: true,
|
||||||
|
remoteStateSyncEnabled: false,
|
||||||
|
remoteStateSyncSource: 'https://dre-1.warp.cc/contract',
|
||||||
|
sequencerUrl: 'https://d1o5nlqr4okus2.cloudfront.net/',
|
||||||
|
sourceType: 'both',
|
||||||
|
stackTrace: {
|
||||||
|
saveState: false
|
||||||
|
},
|
||||||
|
throwOnInternalWriteError: true,
|
||||||
|
unsafeClient: 'skip',
|
||||||
|
updateCacheForEachInteraction: false,
|
||||||
|
useKVStorage: false,
|
||||||
|
waitForConfirmation: false,
|
||||||
|
useConstructor: false,
|
||||||
|
walletBalanceUrl: 'http://nyc-1.dev.arweave.net:1984/'
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
const contract3 = warp.contract(null).setEvaluationOptions({
|
||||||
|
internalWrites: false,
|
||||||
|
unsafeClient: 'throw',
|
||||||
|
gasLimit: 2222,
|
||||||
|
maxCallDepth: 5
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(function () {
|
||||||
|
const result = new EvaluationOptionsEvaluator(contract3.evaluationOptions(), {
|
||||||
|
internalWrites: true
|
||||||
}).rootOptions;
|
}).rootOptions;
|
||||||
}).toThrow('Option {internalWrites} differs.');
|
}).toThrow('Cannot proceed with contract evaluation.');
|
||||||
|
|
||||||
|
expect(function () {
|
||||||
|
const result = new EvaluationOptionsEvaluator(contract3.evaluationOptions(), {
|
||||||
|
unsafeClient: 'allow'
|
||||||
|
}).rootOptions;
|
||||||
|
}).toThrow('Cannot proceed with contract evaluation.');
|
||||||
|
|
||||||
|
expect(function () {
|
||||||
|
const result = new EvaluationOptionsEvaluator(contract3.evaluationOptions(), {
|
||||||
|
unsafeClient: 'skip'
|
||||||
|
}).rootOptions;
|
||||||
|
}).toThrow('Cannot proceed with contract evaluation.');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
it('should properly set foreign evaluation options - unsafeClient - allow', async () => {
|
it('should properly set foreign evaluation options - unsafeClient - allow', async () => {
|
||||||
const contract = warp.contract(null).setEvaluationOptions({
|
const contract = warp.contract(null).setEvaluationOptions({
|
||||||
unsafeClient: 'allow'
|
unsafeClient: 'allow'
|
||||||
|
|||||||
@@ -124,13 +124,35 @@ export class EvaluationOptionsEvaluator {
|
|||||||
if (manifestOptions) {
|
if (manifestOptions) {
|
||||||
const errors = [];
|
const errors = [];
|
||||||
for (const k in manifestOptions) {
|
for (const k in manifestOptions) {
|
||||||
if (this.notConflictingEvaluationOptions.includes(k as keyof EvaluationOptions)) {
|
const optionKey = k as keyof EvaluationOptions;
|
||||||
|
const manifestValue = manifestOptions[k];
|
||||||
|
const userValue = userSetOptions[k];
|
||||||
|
if (this.notConflictingEvaluationOptions.includes(optionKey)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (userSetOptions[k] !== manifestOptions[k]) {
|
// https://github.com/warp-contracts/warp/issues/425#issuecomment-1591212639
|
||||||
errors.push(
|
if (optionKey === 'internalWrites') {
|
||||||
`Option {${k}} differs. EvaluationOptions: [${userSetOptions[k]}], manifest: [${manifestOptions[k]}]. Use contract.setEvaluationOptions({${k}: ${manifestOptions[k]}}) to evaluate contract state.`
|
if (userValue === false && manifestValue === true) {
|
||||||
);
|
throw new Error(
|
||||||
|
'Cannot proceed with contract evaluation. User is blocking internal writes, while contract requires them.'
|
||||||
|
);
|
||||||
|
}
|
||||||
|
} else if (optionKey === 'unsafeClient') {
|
||||||
|
// 'allow' | 'skip' | 'throw'
|
||||||
|
if (
|
||||||
|
(userValue === 'throw' && manifestValue !== 'throw') ||
|
||||||
|
(userValue === 'skip' && manifestValue === 'allow')
|
||||||
|
) {
|
||||||
|
throw new Error(
|
||||||
|
`Cannot proceed with contract evaluation. User requires to ${userValue} on any unsafeClient usage, while contract uses ${manifestValue} option.`
|
||||||
|
);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (userSetOptions[k] !== manifestOptions[k]) {
|
||||||
|
errors.push(
|
||||||
|
`Option {${k}} differs. EvaluationOptions: [${userSetOptions[k]}], manifest: [${manifestOptions[k]}]. Use contract.setEvaluationOptions({${k}: ${manifestOptions[k]}}) to evaluate contract state.`
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (errors.length) {
|
if (errors.length) {
|
||||||
|
|||||||
Reference in New Issue
Block a user