Checksum P2WSH failed
Ok, I've found the problem.

Input has 52 5-bit groups. 260 bits. Remember that every encode calls convertBits to convert from 8 bit groups to 5-bit groups. But 260 bits made of bytes is impossible! So there were 264 bits originally, = 33bytes. 264 bits need to be padded by convertBits (convertBits can/will pad when encoding but won't while decoding). So we have 265 bits. 53 5-bit groups. So you need to add a zero at the end of your input to achieve the intended result.

While decoding, convertBits will, until the number of bits is a multiple of 8, check that the last bit is 0, drop it. In your case, the last bit is not zero, so the only way not to discard it is to pad it, which it's not allowed to do while decoding.

TLDR all 5-bit groups as input are converted from 8-bit groups (addresses are designed for hash outputs and hashes output full bytes). If decoding can't decode to 8-bit groups without padding, the address is considered invalid.



Let's try to do what convertBits does to decode!

First, to simplify ignore first few multiples of 40 bits in the input. The last few bits remaining are:

10000 00110 01001 10001


Convertbits, while decoding converts from 5 to 8:

10000001 10010011 0001


Does the last group have exactly 8 bits? (In that case no further action would be needed) No.
Does the last group have zeros only? (In that case we can just erase the last group) No.
Throw an error. We either need to discard bits or pad, which is not allowed while decoding.

This is why the address you generated is can't be decoded. (Try it)