Skip to content

Commit 1e3cccd

Browse files
committed
Add failing tests for new .slice() feature
1 parent 644e008 commit 1e3cccd

File tree

7 files changed

+90
-0
lines changed

7 files changed

+90
-0
lines changed
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
contract Slice(bytes20 pkh) {
2+
function spend() {
3+
bytes actualPkh = tx.inputs[this.activeInputIndex].lockingBytecode.slice(23);
4+
require(pkh == actualPkh);
5+
}
6+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
contract Slice(bytes20 pkh) {
2+
function spend() {
3+
bytes actualPkh = tx.inputs[this.activeInputIndex].lockingBytecode.slice("3", 23);
4+
require(pkh == actualPkh);
5+
}
6+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
contract Slice(bytes20 pkh) {
2+
function spend() {
3+
int actualPkh = 1921739821792419.slice(1, 3);
4+
require(pkh == actualPkh);
5+
}
6+
}

packages/cashc/test/generation/fixtures.ts

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -825,4 +825,57 @@ export const fixtures: Fixture[] = [
825825
updatedAt: '',
826826
},
827827
},
828+
{
829+
fn: 'double_split.cash',
830+
artifact: {
831+
contractName: 'DoubleSplit',
832+
constructorInputs: [{ name: 'pkh', type: 'bytes20' }],
833+
abi: [{ name: 'spend', inputs: [] }],
834+
bytecode: 'OP_INPUTINDEX OP_UTXOBYTECODE 17 OP_SPLIT OP_DROP OP_3 OP_SPLIT OP_NIP OP_EQUAL',
835+
debug: {
836+
bytecode: 'c0c701177f75537f7787',
837+
sourceMap: '3:36:3:57;:26::74:1;:81::83:0;:26::84:1;:::87;:94::95:0;:26::96:1;:::99;4:8:4:34',
838+
logs: [],
839+
requires: [
840+
{
841+
ip: 10,
842+
line: 4,
843+
},
844+
],
845+
},
846+
source: fs.readFileSync(new URL('../valid-contract-files/double_split.cash', import.meta.url), { encoding: 'utf-8' }),
847+
compiler: {
848+
name: 'cashc',
849+
version,
850+
},
851+
updatedAt: '',
852+
},
853+
},
854+
{
855+
fn: 'slice.cash',
856+
artifact: {
857+
contractName: 'Slice',
858+
constructorInputs: [{ name: 'pkh', type: 'bytes20' }],
859+
abi: [{ name: 'spend', inputs: [] }],
860+
bytecode: 'OP_INPUTINDEX OP_UTXOBYTECODE 17 OP_SPLIT OP_DROP OP_3 OP_SPLIT OP_NIP OP_EQUAL',
861+
debug: {
862+
bytecode: 'c0c701177f75537f7787',
863+
sourceMap: '3:36:3:57;:26::74:1;:84::86:0;:26::87:1;;:81::82:0;:26::87:1;;4:8:4:34',
864+
logs: [],
865+
requires: [
866+
{
867+
ip: 10,
868+
line: 4,
869+
message: undefined,
870+
},
871+
],
872+
},
873+
source: fs.readFileSync(new URL('../valid-contract-files/slice.cash', import.meta.url), { encoding: 'utf-8' }),
874+
compiler: {
875+
name: 'cashc',
876+
version,
877+
},
878+
updatedAt: '',
879+
},
880+
},
828881
];
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
contract DoubleSplit(bytes20 pkh) {
2+
function spend() {
3+
bytes actualPkh = tx.inputs[this.activeInputIndex].lockingBytecode.split(23)[0].split(3)[1];
4+
require(pkh == actualPkh);
5+
}
6+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
contract Slice(bytes20 pkh) {
2+
function spend() {
3+
bytes actualPkh = tx.inputs[this.activeInputIndex].lockingBytecode.slice(3, 23);
4+
require(pkh == actualPkh);
5+
}
6+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
contract Slice(bytes20 pkh) {
2+
function spend() {
3+
int x = 3;
4+
bytes actualPkh = tx.inputs[this.activeInputIndex].lockingBytecode.slice(x, 23);
5+
require(pkh == actualPkh);
6+
}
7+
}

0 commit comments

Comments
 (0)