Skip to content

Commit

Permalink
Merge pull request #158 from ElrondNetwork/cleanup-deprecated
Browse files Browse the repository at this point in the history
Remove deprecated / commented / not used code.
  • Loading branch information
andreibancioiu authored Mar 21, 2022
2 parents 46fdd04 + c43eca7 commit c7c9c5b
Show file tree
Hide file tree
Showing 5 changed files with 1 addition and 322 deletions.
62 changes: 1 addition & 61 deletions src/smartcontracts/codec/binary.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { assert } from "chai";
import { BinaryCodec, BinaryCodecConstraints } from "./binary";
import { AddressType, AddressValue, BigIntType, BigUIntType, BigUIntValue, BooleanType, BooleanValue, I16Type, I32Type, I64Type, I8Type, NumericalType, NumericalValue, Struct, Field, StructType, TypedValue, U16Type, U32Type, U32Value, U64Type, U64Value, U8Type, U8Value, List, ListType, EnumType, EnumVariantDefinition, EnumValue, ArrayVec, ArrayVecType, U16Value, TokenIdentifierType, TokenIdentifierValue, StringValue, StringType } from "../typesystem";
import { discardSuperfluousBytesInTwosComplement, discardSuperfluousZeroBytes, isMsbOne } from "./utils";
import { isMsbOne } from "./utils";
import { Address } from "../../address";
import { Balance } from "../../balance";
import { BytesType, BytesValue } from "../typesystem/bytes";
Expand Down Expand Up @@ -399,64 +399,4 @@ describe("test codec utilities", () => {
buffer.writeBigInt64BE(BigInt("9223372036854775807"));
assert.isFalse(isMsbOne(buffer));
});

it("should discardSuperfluousZeroBytes", async () => {
let buffer: Buffer;

buffer = discardSuperfluousZeroBytes(Buffer.from([0, 0, 0, 1, 2, 3, 4, 5]));
assert.deepEqual(buffer, Buffer.from([1, 2, 3, 4, 5]));
assert.equal(buffer.toString("hex"), "0102030405");

buffer = discardSuperfluousZeroBytes(Buffer.from([0, 0]));
assert.deepEqual(buffer, Buffer.from([]));
assert.equal(buffer.toString("hex"), "");

buffer = discardSuperfluousZeroBytes(Buffer.from([5, 0, 0]));
assert.deepEqual(buffer, Buffer.from([5, 0, 0]));
assert.equal(buffer.toString("hex"), "050000");
});

it("should discardSuperfluousBytesInTwosComplement", async () => {
let buffer: Buffer;

// Negative, -1
buffer = Buffer.alloc(1);
buffer.writeInt8(-1);
assert.deepEqual(buffer, Buffer.from([0xFF]));
assert.deepEqual(discardSuperfluousBytesInTwosComplement(buffer), Buffer.from([0xFF]));

buffer = Buffer.alloc(2);
buffer.writeInt16BE(-1);
assert.deepEqual(buffer, Buffer.from([0xFF, 0xFF]));
assert.deepEqual(discardSuperfluousBytesInTwosComplement(buffer), Buffer.from([0xFF]));

buffer = Buffer.alloc(4);
buffer.writeInt32BE(-1);
assert.deepEqual(buffer, Buffer.from([0xFF, 0xFF, 0xFF, 0xFF]));
assert.deepEqual(discardSuperfluousBytesInTwosComplement(buffer), Buffer.from([0xFF]));

buffer = Buffer.alloc(8);
buffer.writeBigInt64BE(BigInt("-1"));
assert.deepEqual(buffer, Buffer.from([0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF]));
assert.deepEqual(discardSuperfluousBytesInTwosComplement(buffer), Buffer.from([0xFF]));

// Negative, other
buffer = Buffer.from([0b10000000]);
assert.deepEqual(discardSuperfluousBytesInTwosComplement(buffer), Buffer.from([0b10000000]));

buffer = Buffer.from([0b11111111, 0b00000000]);
assert.deepEqual(discardSuperfluousBytesInTwosComplement(buffer), Buffer.from([0b11111111, 0b00000000]));

buffer = Buffer.from([0b11111111, 0b10000000]);
assert.deepEqual(discardSuperfluousBytesInTwosComplement(buffer), Buffer.from([0b10000000]));

// Positive
buffer = Buffer.alloc(1);
buffer.writeInt8(127);
assert.deepEqual(buffer, Buffer.from([0x7F]));
assert.deepEqual(discardSuperfluousBytesInTwosComplement(buffer), Buffer.from([0x7F]));

assert.deepEqual(discardSuperfluousBytesInTwosComplement(Buffer.from([0x00, 0x00, 0xFF])), Buffer.from([0x00, 0xFF]));
assert.deepEqual(discardSuperfluousBytesInTwosComplement(Buffer.from([0x00, 0x00, 0x7F])), Buffer.from([0x7F]));
});
});
35 changes: 0 additions & 35 deletions src/smartcontracts/codec/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,38 +61,3 @@ export function flipBufferBitsInPlace(buffer: Buffer) {
export function prependByteToBuffer(buffer: Buffer, byte: number) {
return Buffer.concat([Buffer.from([byte]), buffer]);
}


/**
* Discards the leading bytes that are merely a padding of the leading sign bit (but keeps the payload).
* @param buffer A number, represented as a sequence of bytes (big-endian)
*/
export function discardSuperfluousBytesInTwosComplement(buffer: Buffer): Buffer {
let isNegative = isMsbOne(buffer, 0);
let signPadding: number = isNegative ? 0xFF : 0x00;

let index;
for (index = 0; index < buffer.length - 1; index++) {
let isPaddingByte = buffer[index] == signPadding;
let hasSignBitOnNextByte = isMsbOne(buffer, index + 1) === isNegative;
if (isPaddingByte && hasSignBitOnNextByte) {
continue;
}

break;
}

return buffer.slice(index);
}

/**
* Discards the leading zero bytes.
* @param buffer A number, represented as a sequence of bytes (big-endian)
*/
export function discardSuperfluousZeroBytes(buffer: Buffer): Buffer {
let index;
for (index = 0; index < buffer.length && buffer[index] == 0; index++) {
}

return buffer.slice(index);
}
13 changes: 0 additions & 13 deletions src/smartcontracts/elrondERC20client.ts

This file was deleted.

118 changes: 0 additions & 118 deletions src/smartcontracts/erc20client.spec.ts

This file was deleted.

95 changes: 0 additions & 95 deletions src/smartcontracts/erc20client.ts

This file was deleted.

0 comments on commit c7c9c5b

Please sign in to comment.