It seems that the varint encoding function would not work for some integers as input. This should in theory fix this issue. Since the SPK IDs are randomly between 0 and 2**32 - 1, it makes sense that the tests fail only sometimes.