aboutsummaryrefslogtreecommitdiffstats
path: root/packages
diff options
context:
space:
mode:
authorGreg Hysen <greg.hysen@gmail.com>2018-11-08 02:49:53 +0800
committerGreg Hysen <greg.hysen@gmail.com>2018-11-29 08:38:10 +0800
commitef5ba0375acbff2f985be08a6bd19b0499628e33 (patch)
treea1f5c7816e35db34ca44431b7b1a8f90ee9f1c66 /packages
parentdfa9e435af7477bddb147a8af3700143b27b5dc6 (diff)
downloaddexon-sol-tools-ef5ba0375acbff2f985be08a6bd19b0499628e33.tar
dexon-sol-tools-ef5ba0375acbff2f985be08a6bd19b0499628e33.tar.gz
dexon-sol-tools-ef5ba0375acbff2f985be08a6bd19b0499628e33.tar.bz2
dexon-sol-tools-ef5ba0375acbff2f985be08a6bd19b0499628e33.tar.lz
dexon-sol-tools-ef5ba0375acbff2f985be08a6bd19b0499628e33.tar.xz
dexon-sol-tools-ef5ba0375acbff2f985be08a6bd19b0499628e33.tar.zst
dexon-sol-tools-ef5ba0375acbff2f985be08a6bd19b0499628e33.zip
Implemented bool type
Diffstat (limited to 'packages')
-rw-r--r--packages/order-utils/test/abi_encoder_test.ts35
1 files changed, 25 insertions, 10 deletions
diff --git a/packages/order-utils/test/abi_encoder_test.ts b/packages/order-utils/test/abi_encoder_test.ts
index 7fb091019..76a6da00e 100644
--- a/packages/order-utils/test/abi_encoder_test.ts
+++ b/packages/order-utils/test/abi_encoder_test.ts
@@ -347,20 +347,18 @@ namespace AbiEncoder {
export class Bool extends StaticDataType {
constructor(dataItem: DataItem) {
super(dataItem);
- expect(Tuple.matchGrammar(dataItem.type)).to.be.true();
+ expect(Bool.matchGrammar(dataItem.type)).to.be.true();
}
- public assignValue(value: string) {
- //const hexValue = ethUtil.bufferToHex(new Buffer(value));
- //this.assignHexValue(hexValue);
+ public assignValue(value: boolean) {
+ const evmWordWidth = 32;
+ const encodedValue = value === true ? '0x1' : '0x0';
+ const hexValue = ethUtil.bufferToHex(ethUtil.setLengthLeft(ethUtil.toBuffer(encodedValue), evmWordWidth));
+ this.assignHexValue(hexValue);
}
public getSignature(): string {
- throw 1;
- }
-
- public encodeToCalldata(calldata: Calldata): void {
- throw 2;
+ return 'bool';
}
public static matchGrammar(type: string): boolean {
@@ -778,7 +776,7 @@ describe.only('ABI Encoder', () => {
});
});
- describe.only('Address', () => {
+ describe('Address', () => {
const testAddressDataItem = { name: 'testAddress', type: 'address' };
it('Valid Address', async () => {
const addressDataType = new AbiEncoder.Address(testAddressDataItem);
@@ -791,6 +789,23 @@ describe.only('ABI Encoder', () => {
});
});
+ describe.only('Bool', () => {
+ const testBoolDataItem = { name: 'testBool', type: 'bool' };
+ it('True', async () => {
+ const boolDataType = new AbiEncoder.Bool(testBoolDataItem);
+ boolDataType.assignValue(true);
+ const expectedAbiEncodedBool = '0x0000000000000000000000000000000000000000000000000000000000000001';
+ expect(boolDataType.getHexValue()).to.be.equal(expectedAbiEncodedBool);
+ });
+
+ it('False', async () => {
+ const boolDataType = new AbiEncoder.Bool(testBoolDataItem);
+ boolDataType.assignValue(false);
+ const expectedAbiEncodedBool = '0x0000000000000000000000000000000000000000000000000000000000000000';
+ expect(boolDataType.getHexValue()).to.be.equal(expectedAbiEncodedBool);
+ });
+ });
+
describe('String', () => {
const testStringDataItem = { name: 'testString', type: 'string' };
it('Less than 32 bytes', async () => {