Skip to content

Commit 27185d6

Browse files
committed
test: add test forward value with lsp17
1 parent 71436a0 commit 27185d6

File tree

3 files changed

+95
-39
lines changed

3 files changed

+95
-39
lines changed

contracts/Mocks/FallbackExtensions/TransferExtension.sol

+3
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,7 @@ contract TransferExtension {
1313
);
1414
balances[msgSender] = amount;
1515
}
16+
17+
// solhint-disable-next-line no-empty-blocks
18+
function receiveFund() public payable {}
1619
}

tests/LSP17ContractExtension/LSP17Extendable.behaviour.ts

+63-30
Original file line numberDiff line numberDiff line change
@@ -162,39 +162,43 @@ export const shouldBehaveLikeLSP17 = (buildContext: () => Promise<LSP17TestConte
162162
});
163163

164164
describe('when making a call with sending value', () => {
165-
it('should pass and emit UniversalReceiver', async () => {
166-
const amountSent = 200;
165+
describe('when extension is not payable', () => {
166+
it('should pass and emit UniversalReceiver', async () => {
167+
const amountSent = 200;
167168

168-
const tx = await context.accounts[0].sendTransaction({
169-
to: context.contract.address,
170-
value: amountSent,
171-
});
169+
const tx = await context.accounts[0].sendTransaction({
170+
to: context.contract.address,
171+
value: amountSent,
172+
});
173+
174+
const isSupportingLSP0 = await context.contract.supportsInterface(
175+
INTERFACE_IDS.LSP0ERC725Account,
176+
);
172177

173-
const isSupportingLSP0 = await context.contract.supportsInterface(
174-
INTERFACE_IDS.LSP0ERC725Account,
175-
);
176-
177-
const isSupportingLSP9 = await context.contract.supportsInterface(INTERFACE_IDS.LSP9Vault);
178-
179-
let emittedTypeId;
180-
if (isSupportingLSP0) {
181-
emittedTypeId = LSP1_TYPE_IDS.LSP0ValueReceived;
182-
} else if (isSupportingLSP9) {
183-
emittedTypeId = LSP1_TYPE_IDS.LSP9ValueReceived;
184-
}
185-
186-
expect(tx)
187-
.to.emit(context.contract, 'UniversalReceiver')
188-
.withArgs(
189-
context.accounts[0].address,
190-
amountSent,
191-
emittedTypeId,
192-
'0x',
193-
abiCoder.encode(
194-
['bytes', 'bytes'],
195-
[ethers.utils.hexlify(ethers.utils.toUtf8Bytes('LSP1: typeId out of scope')), '0x'],
196-
),
178+
const isSupportingLSP9 = await context.contract.supportsInterface(
179+
INTERFACE_IDS.LSP9Vault,
197180
);
181+
182+
let emittedTypeId;
183+
if (isSupportingLSP0) {
184+
emittedTypeId = LSP1_TYPE_IDS.LSP0ValueReceived;
185+
} else if (isSupportingLSP9) {
186+
emittedTypeId = LSP1_TYPE_IDS.LSP9ValueReceived;
187+
}
188+
189+
expect(tx)
190+
.to.emit(context.contract, 'UniversalReceiver')
191+
.withArgs(
192+
context.accounts[0].address,
193+
amountSent,
194+
emittedTypeId,
195+
'0x',
196+
abiCoder.encode(
197+
['bytes', 'bytes'],
198+
[ethers.utils.hexlify(ethers.utils.toUtf8Bytes('LSP1: typeId out of scope')), '0x'],
199+
),
200+
);
201+
});
198202
});
199203
});
200204
});
@@ -457,6 +461,35 @@ export const shouldBehaveLikeLSP17 = (buildContext: () => Promise<LSP17TestConte
457461
});
458462
});
459463

464+
describe('when the extension function is payable', () => {
465+
it('should forward the value to the extension', async () => {
466+
const transferExtension = await new TransferExtension__factory(
467+
context.accounts[0],
468+
).deploy();
469+
470+
await context.contract
471+
.connect(context.deployParams.owner)
472+
.setData(transferFunctionExtensionHandlerKey, transferExtension.address);
473+
474+
const amountTransferred = 20;
475+
476+
const transferFunctionSignature =
477+
transferFunctionSelector +
478+
abiCoder.encode(['uint256'], [amountTransferred]).substring(2);
479+
480+
await context.accounts[0].sendTransaction({
481+
to: context.contract.address,
482+
data: transferFunctionSignature,
483+
});
484+
485+
const balanceAfter = await transferExtension.callStatic.balances(
486+
context.accounts[0].address,
487+
);
488+
489+
expect(balanceAfter).to.equal(amountTransferred);
490+
});
491+
});
492+
460493
describe('when calling an extension that returns a string', () => {
461494
let nameExtension: FakeContract;
462495

tests/LSP17ContractExtension/LSP17Extendable.test.ts

+29-9
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ describe('LSP17Extendable - Basic Implementation', () => {
1717
let exampleExtension: EmitEventExtension;
1818
let errorsExtension: RevertErrorsTestExtension;
1919

20-
const selectorWithExtension =
20+
const selectorWithExtensionAndNoTransferValue =
2121
EmitEventExtension__factory.createInterface().getSighash('emitEvent');
2222
const selectorWithNoExtension = '0xdeadbeef';
2323

@@ -43,12 +43,32 @@ describe('LSP17Extendable - Basic Implementation', () => {
4343
exampleExtension = await new EmitEventExtension__factory(accounts[0]).deploy();
4444
errorsExtension = await new RevertErrorsTestExtension__factory(accounts[0]).deploy();
4545

46-
await lsp17Implementation.setExtension(selectorWithExtension, exampleExtension.address);
47-
48-
await lsp17Implementation.setExtension(selectorRevertCustomError, errorsExtension.address);
49-
await lsp17Implementation.setExtension(selectorRevertErrorString, errorsExtension.address);
50-
await lsp17Implementation.setExtension(selectorRevertPanicError, errorsExtension.address);
51-
await lsp17Implementation.setExtension(selectorRevertNoErrorData, errorsExtension.address);
46+
await lsp17Implementation.setExtension(
47+
selectorWithExtensionAndNoTransferValue,
48+
exampleExtension.address,
49+
false,
50+
);
51+
52+
await lsp17Implementation.setExtension(
53+
selectorRevertCustomError,
54+
errorsExtension.address,
55+
false,
56+
);
57+
await lsp17Implementation.setExtension(
58+
selectorRevertErrorString,
59+
errorsExtension.address,
60+
false,
61+
);
62+
await lsp17Implementation.setExtension(
63+
selectorRevertPanicError,
64+
errorsExtension.address,
65+
false,
66+
);
67+
await lsp17Implementation.setExtension(
68+
selectorRevertNoErrorData,
69+
errorsExtension.address,
70+
false,
71+
);
5272
});
5373

5474
// make sure storage is cleared before running each test
@@ -74,7 +94,7 @@ describe('LSP17Extendable - Basic Implementation', () => {
7494
await expect(
7595
accounts[0].sendTransaction({
7696
to: lsp17Implementation.address,
77-
data: selectorWithExtension,
97+
data: selectorWithExtensionAndNoTransferValue,
7898
}),
7999
).to.emit(exampleExtension, 'EventEmittedInExtension');
80100
});
@@ -89,7 +109,7 @@ describe('LSP17Extendable - Basic Implementation', () => {
89109

90110
await accounts[0].sendTransaction({
91111
to: lsp17Implementation.address,
92-
data: selectorWithExtension,
112+
data: selectorWithExtensionAndNoTransferValue,
93113
});
94114

95115
const storageAfter = await lsp17Implementation.getStorageData();

0 commit comments

Comments
 (0)