Skip to content

Commit

Permalink
Unit tests for generateSchema
Browse files Browse the repository at this point in the history
  • Loading branch information
roxaneletourneau committed Jan 14, 2022
1 parent bc7fa42 commit c8bfc2d
Show file tree
Hide file tree
Showing 43 changed files with 2,459 additions and 213 deletions.
106 changes: 104 additions & 2 deletions packages/taquito-michelson-encoder/test/baker_registry.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ describe('Baker Registry contract test', () => {
const schema = new Schema(storage);
expect(schema.ExtractSchema()).toEqual({
'0': {
big_map : {
big_map: {
key: "key_hash",
value : {
value: {
data: 'bytes',
last_update: 'timestamp',
reporter: 'address',
Expand All @@ -21,6 +21,56 @@ describe('Baker Registry contract test', () => {
signup_fee: 'mutez',
update_fee: 'mutez',
});

expect(schema.generateSchema()).toEqual({
__michelsonType: "pair",
schema: {
'0': {
__michelsonType: "big_map",
schema: {
key: {
__michelsonType: "key_hash",
schema: "key_hash"
},
value: {
__michelsonType: "pair",
schema: {
data: {
__michelsonType: "option",
schema: {
__michelsonType: 'bytes',
schema: "bytes"
}
},
last_update: {
__michelsonType: 'timestamp',
schema: "timestamp"
},
reporter: {
__michelsonType: "option",
schema: {
__michelsonType: 'address',
schema: "address"
}
},
}
},
},
},
owner: {
__michelsonType: 'address',
schema: "address"
},
signup_fee: {
__michelsonType: 'mutez',
schema: "mutez"
},
update_fee: {
__michelsonType: 'mutez',
schema: "mutez"
},
}
});
});

it('Decode storage properly', () => {
Expand Down Expand Up @@ -70,6 +120,58 @@ describe('Baker Registry contract test', () => {
withdraw: 'contract',
});

console.log(JSON.stringify(schema.generateSchema(), null, 2))
expect(schema.generateSchema()).toEqual({
__michelsonType: "or",
schema: {
set_data: {
__michelsonType: "pair",
schema: {
delegate: {
__michelsonType: "key_hash",
schema: 'key_hash'
},
data: {
__michelsonType: "option",
schema: {
__michelsonType: "bytes",
schema: 'bytes'
}
},
reporter: {
__michelsonType: "option",
schema: {
__michelsonType: "address",
schema: 'address'
}
},
}
},
set_fees: {
__michelsonType: "pair",
schema: {
signup_fee: {
__michelsonType: "mutez",
schema: 'mutez'
},
update_fee: {
__michelsonType: "mutez",
schema: 'mutez'
},
}
},
withdraw: {
__michelsonType: "contract",
schema: {
parameter: {
__michelsonType: "unit",
schema: "unit"
}
}
},
}
});

expect(schema.ExtractSignatures()).toContainEqual(['set_data', 'key_hash', 'bytes', 'address']);
expect(schema.ExtractSignatures()).toContainEqual(['set_fees', 'mutez', 'mutez']);
expect(schema.ExtractSignatures()).toContainEqual(['withdraw', 'contract']);
Expand Down
4 changes: 4 additions & 0 deletions packages/taquito-michelson-encoder/test/manager.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ describe('Schema test', () => {
it('Should parse storage schema properly', () => {
const schema = new Schema(storage);
expect(schema.ExtractSchema()).toEqual('key_hash');
expect(schema.generateSchema()).toEqual({
__michelsonType: "key_hash",
schema:'key_hash'
});
});

it('Should parse storage properly', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,55 @@ describe('Token contract with big map', () => {
'2': 'bool',
'3': 'nat',
});

expect(schema.generateSchema()).toEqual({
__michelsonType: 'pair',
schema: {
'0': {
__michelsonType: 'big_map',
schema: {
key: {
__michelsonType: 'address',
schema: 'address'
},
value: {
__michelsonType: 'pair',
schema: {
'0': {
__michelsonType: 'nat',
schema: 'nat'
},
'1': {
__michelsonType: 'map',
schema: {
key: {
__michelsonType: 'address',
schema: 'address'
},
value: {
__michelsonType: 'nat',
schema: 'nat'
},
},
},
}
},
},
},
'1': {
__michelsonType: 'address',
schema: 'address'
},
'2': {
__michelsonType: 'bool',
schema: 'bool'
},
'3': {
__michelsonType: 'nat',
schema: 'nat'
},
}
});
});

it('should encode a big map key properly', () => {
Expand Down
Loading

0 comments on commit c8bfc2d

Please sign in to comment.